checkbox:全选与反全选

时间:2021-11-04 00:40:44
$(document).ready(function () {

    //全选checkbox
$("#selectAll").click(function () {
var checked = $(this).prop("checked");
$(":checkbox").prop("checked", checked);
}); $("tbody :checkbox").click(function () {
var isAllSelected = $("#selectAll").prop("checked");
var selected = $(this).prop("checked");
if (!selected ) {
$("#selectAll").prop("checked", false);
} else {
isAllSelected = true;
$("tbody :checkbox").each(function () {
if (!$(this).prop("checked")) {
isAllSelected = false;
return false;
}
});
$("#selectAll").prop("checked", isAllSelected);
}
}); });