我試圖完全腳本這個複選框檢查/取消選中代碼片段在jQuery中,但它沒有任何成功。這裏是jQuery的/ JavaScript代碼:更優雅的方式(un)在jQuery中檢查?
$.ajax({
type: "GET",
url: "check.xml",
cache: false,
dataType: "xml",
success: function(xml) {
$(xml).find("check").each(function(){
$(xml).find("todo").each(function(){
var state = $(this).attr("state");
if (state == "true") {
document.getElementById($(this).attr("id")).checked = true;
} else {
document.getElementById($(this).attr("id")).checked = false;
}
});
});
}
});
這也可能是非常有可能只使用jQuery的做document.getElementbyId(blablabla)....
。我嘗試這樣做:
($(this).attr("id")).prop("checked", true)
但是,這並沒有真正按預期工作。有什麼建議麼?
http://stackoverflow.com/questions/426258/how-do- i-check-a-checkbox-with-jquery – MSadura
我試過了,但是按照評論,它沒有工作。 – maikovich