如何获取页面上所有已选中复选框的计数 [英] How to get a count of all checked checkboxes on a page

查看:686
本文介绍了如何获取页面上所有已选中复选框的计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想计算用户选择了多少个复选框。例如,如果他选择5,则从一组10个复选框中,我希望能够计算它。使用以下行:

I want to count how many checkboxes a user has selected. For example, from a group of 10 checkboxes if he selects 5, then I want to be able to count it. Using the line:

$(":checkbox:checked")

我可以选择所有选中的复选框,是否有办法获取该语句返回的所有元素的计数?

I can select all of the checked checkboxes, is there a way to get the count of all the elements that are returned by that statement as well?

推荐答案

使用尺寸( )方法或长度属性。长度属性是首选,因为它更快。

Use the size() method or the length property. The length property is preferred as it is faster.

示例:

var count = $("[type='checkbox']:checked").length;

这篇关于如何获取页面上所有已选中复选框的计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆