为了获得具有特定href的<link>元素,可以使用:
document.querySelectorAll("link[href='https://example.com']");假设我有几个具有不同href值的链接,例如:
//example.com/link-3
//example.com/link-4
有什么方法可以让所有的<link>标记在javascript中都有关键字example.com?
发布于 2020-03-26 16:14:24
var elements = document.querySelectorAll('a[href*="example.com"]');
console.log(elements);<a href="https:example.com">test</a>
<a href="https:example.com">test</a>
<a href="https:example.com">test</a>
发布于 2020-03-26 16:14:04
document.querySelectorAll("a[href*='https://example.com']")
提供所有包含example.com的href的css选择器。这将在每个链接中检查https://example.com的子字符串,并选择所有它们。
https://stackoverflow.com/questions/60871454
复制相似问题