
获取 checkbox的选中个数可以直接使用如下jquery语法
$("input[type='checkbox']:checked")length;实例演示如下
创建Html元素
<div class="box"><span>点击按钮获取选中个数:</span><br>
<div class="content">
<input type="checkbox" name="test" >萝卜
<input type="checkbox" name="test" >青菜
<input type="checkbox" name="test" >小葱
<input type="checkbox" name="test" >豆腐
<input type="checkbox" name="test" >土豆
</div>
<input type="button" class="btn" value="获取被选择个数">
</div>
设置css样式
divbox{width:300px;height:250px;padding:10px 20px;margin:20px;border:4px dashed #ccc;}divbox>span{color:#999;font-style:italic;}
divcontent{width:250px;height:100px;margin:10px 0;padding:5px 20px;border:2px solid #ff6666;}
input[type='checkbox']{margin:5px 10px;}
input[type='button']{width:120px;height:30px;margin:10px;border:2px solid #ebbcbe;}
编写jquery代码
$(function(){$("input:button")click(function() {
alert($("input[type='checkbox']:checked")length);
});
})
观察效果
你是想知道选择了多少个checkbox吗?其实谷歌以及许多应用里checkbox都是一个摆设,只是用来响应你点击了哪个item,你点了就setChecked(true),否则就是false,这样你可以在点击item的回调方法里去判断,点击了一下item判断checkbox当前的值,如果显示打勾,则往一个容器里添加一个值,反之移除一个值,最后通过这个容器的size()来显示你给多少个checkbox打勾了。
以上就是关于jquery中怎样获得多选框中,被选择的个数全部的内容,包括:jquery中怎样获得多选框中,被选择的个数、android listview的问题。想在我选择所有的item项里面的checkbox后,获取所有勾选checkbox的值、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)