问题描述
有没有办法使用 querySelector
或 querySelectorAll
进行通配符元素名称匹配?我在属性查询中看到对通配符的支持,但不支持元素本身。
我要解析的XML文档基本上是一个平面的属性列表,我需要找到在他们的名字中有某些字符串的元素。
我意识到如果我需要这个XML文档可能需要重组,但这不会发生。 / p>
任何解决方案,除了回到使用显然不推荐使用的XPath(IE9删除它)是可以接受的。
[id ^ ='someId']
将匹配从 someId
开始的所有ids。
[id $ ='someId']
将匹配以 someId
。
[id * ='someId']
将匹配所有包含 someId
。
如果您要查找名称
属性只需用 name
替换 id
。
如果你在谈论元素的标签名称,我不相信有一种方法使用 querySelector
Is there a way to do a wildcard element name match using querySelector
or querySelectorAll
? I see support for wildcards in attribute queries but not for the elements themselves.
The XML document I'm trying to parse is basically a flat list of properties and I need to find elements that have certain strings in their names.
I realize the XML document is probably in need of a restructuring if I need this but that's just not going to happen.
Any solution except going back to using the apparently deprecated XPath (IE9 dropped it) is acceptable.
[id^='someId']
will match all ids starting with someId
.
[id$='someId']
will match all ids ending with someId
.
[id*='someId']
will match all ids containing someId
.
If you're looking for the name
attribute just substitute id
with name
.
If you're talking about the tag name of the element I don't believe there is a way using querySelector
这篇关于querySelector,通配符元素匹配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!