下面介绍两种使用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>使用jQuery获得选中复选框个数
最新推荐文章于 2022-08-22 19:19:04 发布