可能重複:
How to change the href for a hyperlink using jQuery覆蓋錨的href
我有一個錨標記,其中的href = 「」 像這樣 <a class="SwitchAccountLink" href=""></a>
。我想用jQuery覆蓋這個,並提供一個不同的href。是否有可能重寫錨標籤的內聯href?
在此先感謝。
可能重複:
How to change the href for a hyperlink using jQuery覆蓋錨的href
我有一個錨標記,其中的href = 「」 像這樣 <a class="SwitchAccountLink" href=""></a>
。我想用jQuery覆蓋這個,並提供一個不同的href。是否有可能重寫錨標籤的內聯href?
在此先感謝。
您可以使用jQuery's .attr()
函數來修改元素的特定屬性。
$("a.SwitchAccountLink").attr('href',NEW_URL);
此代碼將取代與的SwitchAccountLink
類的所有錨標籤與NEW_URL
。
如果您只想更改特定鏈接,則可能必須提供更獨特的id
屬性或組合所有鏈接的其他類。
$('.SwitchAccountLink').attr('href', 'http://www.google.com');
你可以改變它做$(".SwitchAccountLink").attr('href','myNewHref');
您可以使用jQuery attr()
來獲取和設置元素的屬性值,詳細瞭解attr()作爲您的錨標記具有我們將用它來上課唯一標識所有類別的錨點SwitchAccountLink
$('.SwitchAccountLink').attr('href', 'Yourhref');
當然,請嘗試:
$('.SwitchAccountLink').attr('href','someurl');
http://api.jquery.com/attr/ – undefined 2012-08-15 16:50:38
@undefined - 忘了再次初始化您的用戶名? ;) – Lix 2012-08-15 16:52:20