checkall

让复选框全部选中和全部取消是比较常用的

JavaScript部分:

1
2
3
function checkAll(obj){
$("#box input[type='checkbox']").prop('checked', $(obj).prop('checked'));
}

html部分:

1
2
3
4
5
6
7
8
9
10
11
12
<div id="box">
<input type="checkbox" onclick="checkAll(this)">全选<br>
<input type="checkbox"><br>
<input type="checkbox"><br>
<input type="checkbox"><br>
<input type="checkbox"><br>
<input type="checkbox"><br>
<input type="checkbox"><br>
<input type="checkbox"><br>
<input type="checkbox"><br>
<input type="checkbox"><br>
</div>