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 32 33 34 35 36 37 38 39 40 41 42 43 44
| $(function () { //全选或全不选 $("#all").click(function(){ if(this.checked){ $("#list :checkbox").attr("checked", true); }else{ $("#list :checkbox").attr("checked", false); } }); //全选 $("#selectAll").click(function () { $("#list :checkbox,#all").attr("checked", true); }); //全不选 $("#unSelect").click(function () { $("#list :checkbox,#all").attr("checked", false); }); //反选 $("#reverse").click(function () { $("#list :checkbox").each(function () { $(this).attr("checked", !$(this).attr("checked")); }); allchk(); });
//设置全选复选框 $("#list :checkbox").click(function(){ allchk(); }); }); function allchk(){ var chknum = $("#list :checkbox").size();//选项总个数 var chk = 0; $("#list :checkbox").each(function () { if($(this).attr("checked")==true){ chk++; } }); if(chknum==chk){//全选 $("#all").attr("checked",true); }else{//不全选 $("#all").attr("checked",false); } }
|