![](/img/trans.png)
[英]How to detect device platform and change link url using JavaScript in AngularJS
[英]How to change the URL of a link using JavaScript?
我需要知道如何更改链接的网址。
例如从www.sitename.com到www.anothersitename.com
我该如何使用JavaScript?
<a id="myAnchor" href="http://www.microsoft.com">Microsoft</a>
<button onclick="myFunction()">Change link</button>
function myFunction() {
//For example How to change Microsoft url to w3 schools url?
//what do i put here?
}
function changeHref() {
document.getElementById("myAnchor").setAttribute("href", "www.google.com")
}
这会将您链接的href
属性设置为google.com。 当然,此URL不得硬编码,并且可以用function参数替换。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.