This question already has an answer here:
这个问题在这里已有答案:
- Can I use an attribute selector for CONTAINS in queryselector()? 1 answer
我可以在queryselector()中使用CONTAINS的属性选择器吗? 1个答案
I'm trying to find a JavaScript element ID and I only know the title.
我正在尝试查找JavaScript元素ID,我只知道标题。
var x = document.querySelectorAll('[title="My Workforce"]');
var id = x.getAttribute('id');
I don't know how to write the title so that it is any approximation of "My Workforce". I have tried using "*" (as in "*My Workforce*"
) but it didn't work. querySelectorAll()
looks for an exact match.
我不知道如何写标题,以便它是“我的劳动力”的任何近似值。我尝试过使用“*”(如“* My Workforce *”),但它没有用。 querySelectorAll()查找完全匹配。
1 个解决方案
#1
0
You can use querySelector()
instead. This allows the use of wildcards, like so:
您可以使用querySelector()代替。这允许使用通配符,如下所示:
https://jsfiddle.net/xtukey8o/
document.querySelector('[title*="My Workforce"]')
#1
0
You can use querySelector()
instead. This allows the use of wildcards, like so:
您可以使用querySelector()代替。这允许使用通配符,如下所示:
https://jsfiddle.net/xtukey8o/
document.querySelector('[title*="My Workforce"]')