jquery 全选/反选/选中所有全选/取消一个取消全选

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//全选
$("#checkall").click(function() {
var checked = $(this).is(":checked");
console.log(checked)
if(!checked){
console.log('没选中')
$("input[name='checkName']").each(function() {
$(this).prop("checked", false);
});
}
else{
console.log('选中')
$("input[name='checkName']").each(function() {
$(this).prop("checked", true);
});
}

});

var chks = $("input[name='checkName']")
chks.click(function(){
for(var i =0 ; i < chks.length ; i++){
if(!chks[i].checked){
console.log('有一个没选')
$("#checkall").prop("checked", false);
return ;
}
}
console.log('都选了 ')
$("#checkall").prop("checked",true);
});