function trClick() {
(this).css("background-color", "#fffde6");//設(shè)置背景色
let checkbox = (checkbox).prop("checked", true);//通常使用prop东囚,attr可能是由于jquery版本的問題有些情況不生效
} else {
(this).siblings().find("input[type='checkbox']").removeAttr("checked");//checkbox取消選中
$(this).css("background-color", "#fffde6");
let checkbox = $(this).find("input[type='checkbox']");
$(checkbox).prop("checked", true);
}
setChxTitleState();
});
}
//動態(tài)添加的元素綁定事件通常是采用:
//(document).on("click", "#field_edit input[type='checkbox']", function () {
if ((this).parents("tr").css("background-color", "#fffde6");
} else {
$(this).parents("tr").css("background-color", "");
}
setChxTitleState();
})
//set column title
function setChxTitleState() {
let checkboxes = document.getElementsByName("ckb");
var checkNum = 0;
for (var i = 0; i < checkboxes.length; i++) {
var checkbox = checkboxes[i];
if (checkbox.checked) {
checkNum++;
}
}
if (checkNum === 0) {
("#check_title").prop("checked", true);
} else {
$("#check_title").prop("checked", false);
}
}