Use of anchor in html, and use of html

Source: Internet
Author: User

Use of anchor in html, and use of html

Now let's summarize several situations of controlling the anchor:

1. On the same page
[Html] view plaincopy

<A name = "add"> </a> <! -- Define the anchor -->
<A href = "# add"> jump to add </a>
2. In different pages, the anchor is located in a.html and jumped from the link of another page to this anchor.
[Html] view plaincopy
<A href = "a.html # add"> jump to a. add </a>
3. Click the link to trigger the js event and jump to the anchor. There are two processing methods:
First:
[Html] view plaincopy
<A href = "# add" onclick = "add ()"> triggers the add function and jumps to the add anchor. </a>
Second:
[Html] view plaincopy
<Div id = "divNode"> <! -- Contents --> </div> <! -- Assume a node to jump to -->
<A href = "#" onclick = "document. getElemetnById ('divnode'). scrollIntoView (true); return false;"> achieve anchpoint effect through scrollIntoView </a>

There are several methods to set the anchor location in html, such as id location, name location, and js location. These methods are not necessarily the most complete. You can refer

1. Locate by id:

<A href = "# 1F" name = "1F"> ANCHOR 1 </a> <div name = "1F"> <p> 11111111111 </br> 11111111111 </br> 11111111111 </br> 11111111111 </br> 11111111111 </br> </p> </div>

Such positioning can be targeted at any tag.

2. Locate using name:


<A href = "# 5F"> anchor 5 </a> </br> </br> </br> <a name = "5F"> 1111111 

The name attribute can only be used to locate tags a, but it cannot be used to locate tags such as div.

3. Use js to locate

<li class="" onclick="javascript:document.getElementById('here').scrollIntoView()"></li> 


Instance:

Smooth js anchor Positioning
<! Doctype html public "-// W3C // dtd html 4.01 // EN"> 




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.