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

jquery code to dynamically obtain the number of selected checkboxes_jquery

WBOY
Release: 2016-05-16 17:31:24
Original
1163 people have browsed it

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>
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template