我是靠谱客的博主 漂亮期待,这篇文章主要介绍动态获取复选框checkbox选中个数的jquery代码,现在分享给大家,希望可以做个参考。

今天碰到“jquery动态获取复选框checkbox选中的个数”,首先看下面例子:

复制代码 代码如下:

<input type="checkbox" checked="checked">python<br>
<input type="checkbox" checked="checked">java<br>
<input type="checkbox" >jquery<br>
<input type="checkbox" >phpddt.com<br>
<script src="jquery.js"></script>
<script>
$(function(){
$("input[type='checkbox']").bind("click",function(){alert($("input[type='checkbox'][checked='checked']").length);});
});
</script>


我给checkbox绑定了点击事件,想获取选中的个数,上面这种写法获取失败,当我点击另外一个复选框,个数任然没变:

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


复制代码 代码如下:

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

最后

以上就是漂亮期待最近收集整理的关于动态获取复选框checkbox选中个数的jquery代码的全部内容,更多相关动态获取复选框checkbox选中个数内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(300)

评论列表共有 0 条评论

立即
投稿
返回
顶部