根据一些数据我正在克隆带有复选框的div并检查数据值是否为“True”然后追加到目标div.
使用jquery 1.5.2
IE8在兼容模式下工作,否则不起作用.
FF不起作用.
$(function () {
// test data
var data = [{ "CB": "True" }, { "CB": "False"}];
var theClone = $("#clone").clone(true);
var temp = "";
if (data !== null) {
$.each(data, function (i, d) {
var cb = theClone.find('.cbClass');
if (d.CB === "True") {
//cb.attr("checked","checked"); //doesn't work
//cb.val(true); //doesn't work
//cb.attr("checked", true); //doesn't work
}
temp += theClone.html();
});
}
$("#target").append(temp);
});