如何获取选中的复选框数组javascript的长度 [英] How can get length on checked checkbox array javascript
本文介绍了如何获取选中的复选框数组javascript的长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<form name='form1' >
<input type=checkbox name='cbox[]' />
</form>
<script>
var checkbox = document.getElementsByName('ckbox[]')
var ln = checkbox.length
alert(ln)
</script>
如何使用JavaScript或jQuery仅计算已选中的复选框?
How can I count only the checked checkboxes with JavaScript or jQuery?
推荐答案
使用jQuery进行操作会缩短代码,并使代码更具可读性,可维护性并且更易于理解.将属性选择器与
Doing it with jQuery would shorten the code and make it more readable, maintainable and easier to understand. Use attribute selector with :checked selector
Live Demo
$('[name="cbox[]"]:checked').length
这篇关于如何获取选中的复选框数组javascript的长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文