jQuery-如何匹配具有属性a或属性b的元素 [英] jQuery - How to match an element has attribute a or attribute b
本文介绍了jQuery-如何匹配具有属性a或属性b的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何编写一个jQuery选择器来匹配具有属性a或属性b的元素.它必须与下面的三个元素匹配
How to write a jquery selector to match an element has attribute a or attribute b. It must match three elements below
<a a="123" b="345"></a>
<a a="123"></a>
<a b="345"></a>
推荐答案
您可以使用多重选择器(,
)与属性等于选择器(或任何其他选择器),例如:
You can use a multiple selector (,
) with the attribute-equals selector (or any other selectors), for example:
$("a[a=123], a[b=345]")
这篇关于jQuery-如何匹配具有属性a或属性b的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文