簡體   English   中英

根據href選擇所有錨標記並進行更改

[英]Select all anchor tags based on href and Change it

我有一個關於基於HREF更改錨標記的URL的問題。

我要選擇所有錨標簽的操作是這樣的:

var anchortags = document.querySelectorAll("a[href*='secureloan.asim.no']");

這樣,我選擇了所有指向secureloan.asim.no的錨標簽。

我還希望在用戶單擊鏈接時更改鏈接(我要刪除參數)

URL的示例可以是:

范例網址:
www.secureloan.asim.no/oasis/index.html#/no/asim?lang=nb-no&product=lev&lanekilde=&campaigncode(etc ....)。

我想從參數中刪除“ lanekilde =“。 即時通訊使用此代碼:

String(document.location.href).replace("&lanekilde=", "");

這給了我正確的URL,但是當他們單擊該網站時,如何為網站上的所有用戶更改它。

到現在為止的代碼ive:

var anchortags= document.querySelectorAll("a[href*='secureloan.remember.no']");
String(document.location.href).replace("&lanekilde=", "");

謝謝 :)

PS:請不要使用Jquery!
PS:如果有人有不同的想法,我會使用標簽管理器

您只需要遍歷節點集並依次更改每個節點集:

var anchortags = document.querySelectorAll("a[href*='secureloan.asim.no']");
anchortags.forEach(function(tag) {
    tag.href = tag.href.replace('&lanekilde=', '');
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM