ITeye博客

反选 并修改选中的数量

bask · 2008-07-03 14:13 · jQuery · Web前端 · Markdown


<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"));
  });

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。