JavaScript Tutorial/HTML Tags/Anchor

Материал из Web эксперт
Перейти к: навигация, поиск

Anchor

An instance of the Anchor object is created with each instance of the <a> tag with the NAME attribute set. An anchor itself is a point in an HTML document that can be reached by using a hypertext link. Anchors allow access to specific parts of Web pages rather than always displaying the top of a document when a Web page is loaded in a browser.

Properties Description name A name that provides access to the anchor from a link text The text that appears between the <a> and </a> tags x The x-coordinate of the anchor y The y-coordinate of the anchor

The following example creates Anchors in a Document.



<html>
    <center>
    Pick a letter:
    <a href="#A">A</a>|<a href="#B">B</a>|<a href="#C">C</a>
    </center>
    <hr><a name="A"><h4>The Letter A</h4></a>
    A<br>
     B<br>
    <hr><a name="B"></a>
    C<br>
    D<br>
    F<br>
    C<br>
    D<br>
    F<br>
    C<br>
    D<br>
    F<br>
    C<br>
    D<br>
    F<br>
    C<br>
    D<br>
    F<br>
    C<br>
    D<br>
    F<br>
    C<br>
    D<br>
    F<br>
    C<br>
    D<br>
    F<br>
    C<br>
    D<br>
    F<br>
    C<br>
    D<br>
    F<br>
    C<br>
    D<br>
    F<br>
    C<br>
    D<br>
    F<br>
    C<br>
    D<br>
    F<br>
    C<br>
    D<br>
    F<br>
    C<br>
    D<br>
    F<br>
    C<br>
    D<br>
    F<br>
    C<br>
    D<br>
    F<br>
    C<br>
    D<br>
    F<br>
    C<br>
    D<br>
    F<br>
    <hr><a name="C"></a>
    G<br>
    H<br>
    <script language="JavaScript">
    <!--
    document.write("<hr>The Anchor Properties:<br>");
    for(var counter=0; counter<=document.anchors.length; counter++)
    {
      document.write("anchors[",counter,"].name=");
      document.write(document.anchors[counter].name,"<br>");
      document.write("anchors[",counter,"].text=");
      document.write(document.anchors[counter].text,"<br>");
      document.write("anchors[",counter,"].x=");
      document.write(document.anchors[counter].x,"<br>");
      document.write("anchors[",counter,"].y=");
      document.write(document.anchors[counter].y,"<br>");
    }
    -->
    </script>
    </html>


Anchor.name

Syntax



document.anchors[num].name


Anchor.text

Syntax



document.anchors[num].text


Anchor.x

Syntax



document.anchors[num].x


Anchor.y

Syntax



document.anchors[num].y