我正在尝试使用jQuery查找元素,但它不起作用。我发现这种选择器不能在Greasemonkey中完成:
($("#app7019261521_hover_container > [id^=app7019261521_the_coin]"))
请帮我把这个翻译成原始的Javascript。这种选择器在Javascript中是很难做到的。请帮帮我Javascript大师!
发布于 2009-08-14 19:52:09
这应该可以做到,现在我记起为什么我开始使用jQuery了:
var children = document.getElementById('app7019261521_hover_container').childNodes;
var ids = []; //to store the IDs of all matching elements
for(var i = 0; i < children.length; i++)
{
//indexOf returns zero is subject starts with passed string
if(children.item(i).id.indexOf('app7019261521_the_coin') == 0)
{
alert('Got One!');
ids.push(children.item(i).id);
}
}
发布于 2009-08-14 20:14:09
由于您的目标是直接针对Firefox,因此您可能希望了解一下在Firefox 3.5上实现的Selectors API。
检查document.querySelectorAll函数:
var elements = document.querySelectorAll("#app7019261521_hover_container > [id^=app7019261521_the_coin]")
https://stackoverflow.com/questions/1281098
复制相似问题