jQuery,有没有一种方法可以选择具有特定属性的页面上的所有元素? [英] JQuery, is there a way to select all elements on the page with a specific attribute?
本文介绍了jQuery,有没有一种方法可以选择具有特定属性的页面上的所有元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我创建类似:
<div>
<p myAttribute='Hello'>Text</p>
..
</div>
然后,我想在页面上查找所有具有myAttribute的元素,无论它们是什么.我该怎么做?
I then want to find on my page, all elements that have myAttribute, regardless of what they are. How do I do this?
推荐答案
您可以使用具有属性选择器,例如:
$("[myAttribute]")
要获取具有该属性的特定值的元素,请使用 attribute-equals选择器,如下所示:
To get elements with that attribute with that specific value, use the attribute-equals selector, like this:
$("[myAttribute='Hello']")
这篇关于jQuery,有没有一种方法可以选择具有特定属性的页面上的所有元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文