[英]How do I select all angular fields on an HTML page using a certain class in javascript/jquery?
[英]How do I select all links on page that contain a certain word?
如何選擇頁面上包含特定關鍵字的所有鏈接。 我想要所有鏈接中包含“ amazon”的鏈接。 有些鏈接可能是https或http,所以我不能這樣做
let amazonLinks = document.querySelectorAll('[href*="https://www.amazon"]');
您可以使用以下選擇器選擇頁面中的所有鏈接:
document.querySelectorAll('a[href*="amazon"]').forEach(function(a){
console.log(a.href)});
干杯! 希望這可以幫助...
以下是querySelector的通配符:
[attr^='someValue']
將匹配所有以someId開頭的ID。
[attr$='someValue']
將匹配所有以someId結尾的ID。
[attr*='someValue']
將匹配所有包含someId的ID。
如果您需要http
或https
,則應查詢://amazon.com
使用jQuery:
$('a[href*="/YOUR-TEXT-HERE/"]').attr('href')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.