The DOM anchor objects

Anchor object is
Anchor object represents an HTML hyperlink.
HTML document tags appear every time, it will create Anchor objects.
Link anchor can be used to create a link to another document (by the href attribute), or create bookmarks (by name attributes) within a document.
You can [] array by searching the Document object to access the anchor of anchors, or use document.getElementById ().

anchor objects running instance:

  <html>
    <body>
    <a name="first">第一个锚</a><br />
    <a name="second">第二个锚</a><br />
    <a name="third">第三个锚</a><br />
    <br />
    文档中锚的数目:
    <script type="text/javascript">
    document.write(document.anchors.length)
    </script>
    </body>
    </html>

Run Example 2:

<html>
<meta charset="UTF-8">
<body>
<a name="first">第一个锚</a><br />
<a name="second">第二个锚</a><br />
<a name="third">第三个锚</a><br />
<br />

本文档中第一个锚的 InnerHTML 是:
<script type="text/javascript">
    document.write(document.anchors[0].innerHTML)
</script>
</body>
</html>
Published 74 original articles · won praise 27 · views 9523

Guess you like

Origin blog.csdn.net/qq_42526440/article/details/100823079