|
|
<script> var j=0//全局使用 jQuery(function ($) { //加载触发 $("input[@type='checkbox']").each(function() { if($(this).attr("checked")) { j++; } else { j--; } $("#count").html(""+j); }); $("#count").html(""+j); //反选 $("#otherCheck").click(function(){ j = 0; $("input[@type='checkbox']").each(function() { if($(this).attr("checked")) { $(this).attr("checked",false); } else { $(this).attr("checked",true); j++; } }); $("#count").html(""+j); }); }); </script>
<span id="count"></span><input type="checkbox" /><input type="button" id="otherCheck" value="反选" />
如果只是反选
$("input[@type='checkbox']").each(function() { $(this).attr("checked",!$(this).attr("checked")); }); |
|