bask 发表于 2013-2-7 15:14:26

反选 并修改选中的数量

<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"));});
页: [1]
查看完整版本: 反选 并修改选中的数量