querySelector,通配符元素匹配? [英] querySelector, wildcard element match?

查看:1402
本文介绍了querySelector,通配符元素匹配?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法使用 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,通配符元素匹配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆