HTML DOM 錨物件


HTML 中的 <a> 元素用於建立超連結,同時使用超連結引用屬性。錨物件表示此 <a> 元素。

舉例

在下例中,我們將瞭解如何訪問錨物件 −

 現場演示

<!DOCTYPE html>
<html>
<body>
<h2>Demo Heading</h2>
<a href="https://google.com" id = "myid" >Google</a><br><br>
<button onclick="display()">Display the link</button>
<p id="demo">Link gets displayed here</p>
<script>
   function display() {
      var a = document.getElementById("myid").href;
      document.getElementById("demo").innerHTML = a;
   }
</script>
</body>
</html>

輸出

這將生成以下輸出 −

更新於: 2019-09-17

132 次瀏覽

開啟你的 職業生涯

透過完成課程獲得認證

開始行動
廣告
© . All rights reserved.