Home  >  Article  >  Web Front-end  >  jquery code to dynamically obtain the number of selected checkboxes_jquery

jquery code to dynamically obtain the number of selected checkboxes_jquery

WBOY
WBOYOriginal
2016-05-16 17:31:241160browse

Today I encountered "jquery dynamically obtains the number of selected checkboxes", first look at the following example:

Copy code The code is as follows:

python

java

jquery

phpddt.com


<script> <br>$(function(){ <br>$("input[type='checkbox']").bind("click ",function(){alert($("input[type='checkbox'][checked='checked']").length);}); <br>}); <br></script>


I bound a click event to the checkbox and wanted to get the number of selected items. The above method failed to obtain it. When I clicked another checkbox, the number remained unchanged:

jquery动态获取复选框checkbox选中的个数


Copy code The code is as follows:

<script> <br>$( function(){ <br>$("input[type='checkbox']").bind("click",function(){alert($("input[type='checkbox']:checked").length );}); <br>}); <br></script>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn