HTML DOM 锚点对象

htmlweb developmentfront end technology更新于 2025/11/25 7:08:17

HTML 中使用 <a> 元素以及 href 属性创建超链接。锚点对象代表此 <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>

输出

这将产生以下输出 −


相关文章


有用资源