删除Javascript中属性值为cite_uu的所有元素

删除Javascript中属性值为cite_uu的所有元素,javascript,css-selectors,Javascript,Css Selectors,我有以下代码: document.querySelectorAll(" img, [href='#cite'] ").forEach(function(el) { el.style.display = "none"; }); 在这段代码中,您可以看到属性值通配符[href='cite-'] 此选择器类似于维基百科文章中的源引用 上述代码不起作用,因此不会删除包含以cite开头的href的所有元素 -您可以看到,所有源引用和注释通常称为引文,因此术语cite具有citeMething的h

我有以下代码:

document.querySelectorAll(" img, [href='#cite'] ").forEach(function(el) {
    el.style.display = "none";
});
在这段代码中,您可以看到属性值通配符[href='cite-']

此选择器类似于维基百科文章中的源引用

上述代码不起作用,因此不会删除包含以cite开头的href的所有元素

-您可以看到,所有源引用和注释通常称为引文,因此术语cite具有citeMething的href值

我的问题是,是否有可能将href属性的所有a标记和以cite开头的所有值作为目标。

用于选择属性值以特定值开头的所有元素

document.querySelectorAll("img,[href^='#cite'] ").forEach(function(el) {
//                          -------^^^^^-------
    el.style.display = "none";
});
对于旧的浏览器支持,您需要将节点列表转换为数组,因为它不广泛支持

[].slice.call(document.querySelectorAll("img,[href^='#cite'] ")).forEach(function(el) {
    el.style.display = "none";
});
使用href=cite查询元素

document.querySelectorAll'[href^=cite]'

使用href=cite查询标记a元素

document.querySelectorAll'a[href^=cite]'


querySelectorAll返回一个节点列表,它支持forEach:除IE外。通配符选择器是什么意思?您指的是问题中的标题和1个位置;当我想问一个我已经成功使用的CSS通配符时,这个问题一直没有解决。我现在修正了这个问题。语法通配符选择器是个错误,我想我应该把它改成属性值通配符。我仍然不确定通配符是什么意思。[href='cite-']查找href属性完全为cite-的所有元素。是的,我需要一个通配符,以便以这个短语cite-开头的所有内容都将成为目标,因为Wiki文章与这个词有一些不同之处。