开发者

How do I pass the value of a variable to an specific page element with solely JavaScript?

开发者 https://www.devze.com 2023-01-11 17:27 出处:网络
Let\'s say I have: var url="http://www.google.html"; how do I put the URL variable value as the href value of a specific anchor tag in the page?

Let's say I have:

var url="http://www.google.html";

how do I put the URL variable value as the href value of a specific anchor tag in the page? I know about str.link() but how can I use that with a specific element? And can I use link*( to build anch开发者_Python百科ors of images? That didn't seem to work for me. Thanks for the help


For anchor elements:

<a id="myAnchor">link me!</a>

...

<script type="text/javascript">
var url = "http://www.google.html";  // .html is the new .com
var myAnchor = document.getElementById('myAnchor');
myAnchor.href = url;
</script>
0

精彩评论

暂无评论...
验证码 换一张
取 消