checkbox 全选、全不选、子项全选则全选按钮也选中

HTML:

全选


JS:

// 表格全选,反选
function checkAll(str, ev) {
var a = document.getElementsByName(str);
var n = a.length;
var target = ev.srcElement || ev.target;
for (var i = 0; i < n; i++)
a[i].checked = target.checked;
}
function checkItem(str, ev) {
var e = ev.srcElement || ev.target;
var all = eval("document.all." + str);
if (e.checked) {
var a = document.getElementsByName(e.name);
all.checked = true;
for (var i = 0; i < a.length; i++) {
if (!a[i].checked) {
all.checked = false;
break;
}
}
} else
all.checked = false;
}


你可能感兴趣的:(java学习笔记)