document.anchors

收藏:0   阅读:29

HTML DOM anchors 集合


定义和用法

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

© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!