jquery 计数具有属性的元素 [英] jquery count elements with attribute

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

问题描述

我可以计算具有特定属性的元素的数量吗?

Can I count the number of elements with a specific attribute?

例如所有带有 src 属性 test.gif 的图像

For example all the images with the src attribute test.gif

推荐答案

使用 CSS 属性选择器对属性进行过滤

Use the CSS attribute selectors to filter on the attribute

$("img[src='test.gif']").length;

size()length 都返回匹配的元素个数;

the size() and length both returns the number of elements matched;

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

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