簡體   English   中英

將 href 替換為同一頁面中的另一個 href

[英]Replace href with another href from the same page

我想制作一個具有與另一個按鈕相同的 href 的按鈕。

我的網站上有一個按鈕,並非所有用戶都能看到,但它幾乎隱藏且難以觸及。 此按鈕具有每個用戶的特定 UR 並包含他的 ID。 在另一個頁面上,我想創建一個按鈕,該按鈕將從另一個按鈕復制相同的 href:

這是一個例子:

<div class="row exsisting-button button-hard-to-reach">
    <a href="https://doman.com/user/543456/offers" class="your-offers">See my offers</a>
</div>


<div class="row new-button">
    <a href="" class="new-button">Here are you offers</a>
</div>

您可以使用 querySelector 來查找元素和 getAttribute getAttribute 來設置 get href

 document.querySelector('.btn-href').setAttribute('href', document.querySelector('.your-offers').getAttribute('href') );
 <div class="row exsisting-button button-hard-to-reach"> <a href="https://doman.com/user/543456/offers" class="your-offers">See my offers</a> </div> <div class="row new-button"> <a href="" class="new-button btn-href">Here are you offers</a> </div>

暫無
暫無

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

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