Setting events for html hyperlinks does not use href for Skip.

Source: Internet
Author: User

Sometimes, we need to use the <a> hyperlink instead of href to complete the jump, for example, <a href = "#" onClick = "fun () "> </a>. In this way, the page will not jump. But it also brings some negative problems, such as the title of the page becoming "#", or the scroll bar or something on the page. This is because after the onClick event is executed, <a> jump to the address pointed to by href, and "#" is an anchor. By default, it is the top of the web page, so it will bring the problems mentioned above.

There are two solutions:

1. Add the return false statement to the onClick event, for example:
Copy codeThe Code is as follows:
<A href = "#" onClick = "fun (); return false;"> click </a>

2. Use void (0) instead of #, for example:
Copy codeThe Code is as follows:
<A href = "javascript: void (0)" onclick = "fun ()"> click </a>

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.