HTML DOM anchors collection
Definition and Usage
It returns a collection of all the anchors hyperlinks array current page.
grammar
document.anchors[].property
Browser Support
All major browsers support anchors collection
Examples
Example 1
Returns the number of linked documents:
<! DOCTYPE html>
<Html>
<Head>
<Meta charset = "utf-8">
<Title> This tutorial (w3big.com) </ title>
</ Head>
<Body>
<a name="html"> HTML tutorial </a> <br>
<a name="css"> CSS tutorial </a> <br>
<a name="xml"> XML tutorial </a> <br>
<a href="/js/"> JavaScript tutorial </a>
<P> Number of anchors:
<Script>
document.write (document.anchors.length);
</ Script> </ p>
</ Body>
</ Html>
<Html>
<Head>
<Meta charset = "utf-8">
<Title> This tutorial (w3big.com) </ title>
</ Head>
<Body>
<a name="html"> HTML tutorial </a> <br>
<a name="css"> CSS tutorial </a> <br>
<a name="xml"> XML tutorial </a> <br>
<a href="/js/"> JavaScript tutorial </a>
<P> Number of anchors:
<Script>
document.write (document.anchors.length);
</ Script> </ p>
</ Body>
</ Html>
Examples of the above output:
锚的数量: 3
try it"
Example 2
Return the document in the first link anchor text:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</title>
</head>
<body>
<a name="html">HTML 教程</a><br>
<a name="css">CSS 教程</a><br>
<a name="xml">XML 教程</a>
<p>文档中第一个锚:
<script>
document.write(document.anchors[0].innerHTML);
</script>
</p>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</title>
</head>
<body>
<a name="html">HTML 教程</a><br>
<a name="css">CSS 教程</a><br>
<a name="xml">XML 教程</a>
<p>文档中第一个锚:
<script>
document.write(document.anchors[0].innerHTML);
</script>
</p>
</body>
</html>
Examples of the above output:
文档中第一个锚: HTML 教程
try it"
Document Object