用jQuery计数元素 [英] Count elements with jQuery

查看:65
本文介绍了用jQuery计数元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以计算页面上具有特定类的元素的数量?

Is there a way to count how many elements on the page with a particular class?

推荐答案

$('.someclass').length

您还可以使用:

$('.someclass').size()

在功能上是等效的,但前者是首选.实际上,后者现已已弃用,并且不应在任何新开发中使用.

which is functionally equivalent, but the former is preferred. In fact, the latter is now deprecated and shouldn't be used in any new development.

这篇关于用jQuery计数元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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