jquery全选、反选、全不选
Jquery代码
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
!function ($) { //全选 反选 全不选 $("#selAll").click(function () { $(".lists :checkbox").not(':disabled').prop("checked", true); }); $("#unSelAll").click(function () { $(".lists :checkbox").not(':disabled').prop("checked", false); }); $("#reverSel").click(function () { //遍历.lists下的 checkbox; $(".lists :checkbox").not(':disabled').each(function () { $(this).prop("checked", !$(this).prop("checked")); }); });}(jQuery) |
html
|
1
2
3
4
5
6
7
8
9
|
<input class="btn btn-default" id="selAll" type="button" value="全选" /><input class="btn btn-default" id="unSelAll" type="button" value="全不选" /><input class="btn btn-default" id="reverSel" type="button" value="反选" /><div class="lists"> <input type="checkbox" value="1" /> 苹果 <input type="checkbox" value="2" /> 香蕉 <input type="checkbox" value="3" /> 菠萝 <input type="checkbox" value="4" /> 桃子</div> |
后来都会美好的!
浙公网安备 33010602011771号