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

查看:126
本文介绍了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() 长度 都返回匹配的元素数量;

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

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

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