可能重复:
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