HTML DOM Anchor href 屬性
定義和用法
href 屬性可設置或返回鏈接中href 屬性的值。
href 屬性指定了被鏈資源的URL。
語法
設置href 屬性:
anchorObject.href="URL"
返回href 屬性:
anchorObject.href
值 | 描述 |
---|---|
URL | 被链资源的 URL |
瀏覽器支持
所有主要瀏覽器都支持href 屬性
實例
實例
返回鏈接中href 屬性的值:
<html>
<body>
<p><a id="w3s" href="http://www.w3cschool.cc/">W3Schools.com</a></p>
<script>
document.write(document.getElementById("w3s").href);
</script>
</body>
</html>
<body>
<p><a id="w3s" href="http://www.w3cschool.cc/">W3Schools.com</a></p>
<script>
document.write(document.getElementById("w3s").href);
</script>
</body>
</html>
以上實例輸出結果:
http://www.w3cschool.cc/
嘗試一下»
Anchor對象