在querySelectorAll中使用冒号

问题描述:

我试图使用querySelectorAll()方法来抓取网页中的链接,但我想忽略以“javascript:”开头的链接或使用其他协议,如“itpc://”在querySelectorAll中使用冒号

有没有什么办法可以将它们包含在“not()”伪选择器中?

document.querySelectorAll("a:not([href^=javascript]):not([href^=itpc])"); //works 
document.querySelectorAll("a:not([href^=javascript:]):not([href^=itpc://])"); //doesn't work 

即使第一方法工作在当前页面上罚款,也不能保证它会我会用它在每一页上工作,所以我真的很想能够检测出结肠。

基于the spec,把你要定位strings值将工作:

document.querySelectorAll("a:not([href^='javascript:']):not([href^='itpc://'])"); 

与当前版本的问题是,除非你使用引号的值必须符合放在identifiers的限制,他们没有。

+0

完全错过了。谢谢! – 2012-03-19 01:05:00