jQuery:选择具有自定义属性的所有元素 [英] jQuery : select all element with custom attribute
本文介绍了jQuery:选择具有自定义属性的所有元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请考虑以下代码:
<p>11111111111111</p>
<p MyTag="nima">2222222222</p>
<p>33333333333</p>
<p MyTag="Sara">>4444444444</p>
我如何选择所有 p
标签属性 MyTag
?
how I can select All p
tag with attribute MyTag
?
谢谢
推荐答案
使用具有属性选择器:
$('p[MyTag]')
或者选择该属性具有特定值的一个:
Or to select one where that attribute has a specific value:
$('p[MyTag="Sara"]')
有其他选择器,属性值以开头,属性值包含等等。
There are other selectors for "attribute value starts with", "attribute value contains", etc.
这篇关于jQuery:选择具有自定义属性的所有元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文