jquery 计数具有属性的元素
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2030691/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 12:37:56 来源:igfitidea点击:
jquery count elements with attribute
提问by usertest
Can I count the number of elements with a specific attribute?
我可以计算具有特定属性的元素的数量吗?
For example all the images with the src attribute test.gif
例如所有带有 src 属性 test.gif 的图像
回答by chakrit
回答by Dave.Sol
if you want to check the presence of the attribute only
如果您只想检查属性是否存在
$('img[src]').length //or .size()
回答by easement
You want size() so something like:
你想要 size() 这样的东西:
something like:
就像是:
$('img[src="test.gif"]').size();