在chrome中,没有错误,没有警告,甚至没有信息。它就是不起作用。
$(document).ready(function () {
var cbxAdmins = $("input[name^=hasAdmin][type=checkbox]");
for (var i = 0; i < cbxAdmins.Length; i++) {
cbxAdmins[i].click(function () {
var checkAll = this.checked;
var permiCheckboxes = $(this).parents("tr:first").find(':checkbox');
if (checkAll) {
$(permiCheckboxes).attr('checked', true);
}
else {
$(permiCheckboxes).attr('checked', '');
}
});
}
});发布于 2012-09-05 16:20:44
您不需要跨数组中的所有元素使用for循环,jQuery足够智能,可以单独应用单击事件。试试这个:
$(document).ready(function () {
$("input[name^=hasAdmin][type=checkbox]").click(function () {
$(this).closest("tr").find('[type=checkbox]').prop('checked', this.checked);
});
});多亏了Fabricio Matte,我也理清了一些逻辑。
https://stackoverflow.com/questions/12277222
复制相似问题