在querySelectorAll()中使用冒号
Using colons in querySelectorAll()
本文关键字:querySelectorAll 更新时间:2023-09-26
我正试图使用querySelectorAll()
方法来获取网页中的链接,但我想忽略以"javascript:"开头的链接,或者使用另一种协议,如"itpc://"
有没有办法将这些包含在"not()"伪选择器中?
document.querySelectorAll("a:not([href^=javascript]):not([href^=itpc])"); //works
document.querySelectorAll("a:not([href^=javascript:]):not([href^=itpc://])"); //doesn't work
尽管第一种方法在当前页面上运行良好,但不能保证它在我使用它的每一页上都能运行,所以我真的希望能够检测到冒号。
根据规范,将您想要的值转换为字符串将起作用:
document.querySelectorAll("a:not([href^='javascript:']):not([href^='itpc://'])");
当前版本的问题是,除非使用引号,否则值必须符合对标识符的限制,而事实并非如此。
相关文章:
- 如何从querySelectorAll中获取按钮类型
- 使用querySelectorAll为图像源添加前缀
- querySelectorAll不适用于指定的元素
- .querySelectorAll如何只获取具有所有属性的元素
- 如何使用 document.querySelectorAll 遍历选定的元素
- JavaScript-querySelectorAll和小写/大写
- 如何在JS中修饰querySelector/querySelectorAll
- querySelectorAll在Firefox Addon中返回带有空对象的数组
- 使用 querySelectorAll 后无法将元素推送到数组
- document.querySelectorAll polyfill
- jQuery类选择器如何比querySelectorAll的jQuery包装器更快?
- document.querySelectorAll() 函数不适用于所有元素
- querySelectorAll:查找子级,直到遇到某个阈值元素
- Array.prototype.splice.call-不适用于querySelectorAll('.class
- querySelectorAll()从另一个页面转换为html
- querySelectorAll返回空节点列表
- 对象没有't支持属性或方法'querySelectorAll'(sp.core.debug.js
- document.querySelectorAll(variable class)
- 使用querySelectorAll进行的复选框选择不起作用
- 我可以在文档中放入逻辑运算符吗.querySelectorAll?如果是,如何