version 0.1.0:
//调用
var $allC = $("input.allchecked");
var $angleC = $("div input[type='checkbox']");
checkAll($allC, $angleC);
});
//全选
function checkAll(all, ones) {
all.live("click", function () {
if (this.checked) {
ones.attr({ "checked": "checked" });
all.attr({ "checked": "checked" });
} else {
ones.removeAttr("checked");
all.removeAttr("checked");
}
});
ones.live("click", function () {
if (this.checked && ones.not(":checked").length == 0) {
all.attr({ "checked": "checked" });
} else {
all.removeAttr("checked");
}
});
}
versin 0.0.1:
// 调用
checkAll($("#allcheck"), $("table tbody input[type='checkbox']"));
//全选全不选
function checkAll(all, ones) {
all.click(function () {
if (this.checked) {
$(ones).attr({ "checked": "checked" });
} else {
$(ones).removeAttr("checked");
}
});
ones.click(function () {
if (this.checked && ones.not(":checked").length == 0) {
all.attr({ "checked": "checked" });
} else {
all.removeAttr("checked");
}
});
}