HTML DOM anchors 集合

Document 对象 参考手册 Document 对象

定义和用法

anchors集合返回了当前页面的所有超级链接数组 。

语法

document.anchors[].property


浏览器支持

Internet ExplorerFirefoxOperaGoogle ChromeSafari

所有主要浏览器都支持 anchors 集合


实例

实例 1

返回文档的链接数:

<html>
<body>

<a name="html">HTML Tutorial</a><br>
<a name="css">CSS Tutorial</a><br>
<a name="xml">XML Tutorial</a><br>

<p>Number of anchors:
<script>
document.write(document.anchors.length);
</script></p>

</body>
</html>

以上实例输出结果:

Number of anchors: 3

尝试一下 »

实例 2

返回文档中第一个超级链接的锚文本:

<html>
<body>

<a name="html">HTML Tutorial</a><br>
<a name="css">CSS Tutorial</a><br>
<a name="xml">XML Tutorial</a><br>

<p>innerHTML of first anchor:
<script>
document.write(document.anchors[0].innerHTML);
</script></p>

</body>
</html>

以上实例输出结果:

InnerHTML of first anchor: HTML Tutorial

尝试一下 »


Document 对象 参考手册 Document 对象