我试图完全脚本这个复选框检查/取消选中代码片段在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