如何计数使用jQuery的复选框? [英] How to count check-boxes using jQuery?
本文介绍了如何计数使用jQuery的复选框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有大量的复选框被选中( checked =checked
)或取消选中。
I have tons of check-boxes that are either checked (checked="checked"
) or unchecked.
我想获得所有复选框的数量,未选中和选中的复选框。
I would like to get number of all check-boxes, unchecked and checked check-boxes.
对于复选框,我的意思是 input type =checkbox/>
。
With check-box I mean <input type="checkbox" />
.
如何使用jQuery?感谢您的建议!
How to do it with jQuery? Thanks in an advice!
推荐答案
您可以:
var numberOfChecked = $('input:checkbox:checked').length;
var totalCheckboxes = $('input:checkbox').length;
var numberNotChecked = totalCheckboxes - numberOfChecked;
EDIT
p>
Or even simple
var numberNotChecked = $('input:checkbox:not(":checked")').length;
这篇关于如何计数使用jQuery的复选框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文