使用jQuery获得选中复选框个数

来源:互联网 发布:多玩魔兽盒子mac版 编辑:程序博客网 时间:2024/05/18 19:44

下面介绍两种使用jQuery来获取页面中选中复选框个数的方法:

<html><head>      <title>test</title>      <script src="jquery-1.3.2.min.js" type="text/javascript"></script><script type="text/javascript">//方法一$(function(){$("#GetButton_1").click(function(){     var CheckCount=0;     $("[name='ChooseOne']").each(function(){        if($(this).attr("checked")){            CheckCount++;        }     });     alert(CheckCount);});});//方法二$(function(){$("#GetButton_2").click(function(){     alert($("input[name='ChooseOne']:checked").length);});});</script></head><body><input type="checkbox" name="ChooseOne" ><input type="checkbox" name="ChooseOne" ><input type="checkbox" name="ChooseOne" ><input type="checkbox" name="ChooseOne" ><input type="checkbox" name="ChooseOne" ><br><input name="GetButton_1" id="GetButton_1" type="button" value="方法一"><input name="GetButton_2" id="GetButton_2" type="button" value="方法二"></body></html>


 

原创粉丝点击