开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜