用jQuery实现全选和取消全选
2019-08-13 本文已影响0人
欣_m
全选 取消全选
checkAll是全选按钮的id
check是每个checkbox的class名
prop()方法可以用于设置属性,也可以用于判断是否存在某个属性
each()方法遍历每个class名为check的元素
$("#checkAll").on("click", function () {
if ($("#checkAll").prop("checked")) {
$(".check").each(function () {
$(this).prop("checked", true);
})
var arr = "";
var name = $(".name").text();
arr += name;
console.log("姓名:" + arr);
} else {
$(".check").each(function () {
$(this).prop("checked", false);
})
}
})