Setting events for html hyperlinks does not use href for Skip-javascript

Source: Internet
Author: User
Sometimes we need to use the hyperlink a without using href to complete the jump. To solve this problem, we can use the following solution. Sometimes we need to use this hyperlink, instead of using href to complete the jump, this method is used. 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, It redirects 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:

The Code is as follows:


Click


2. Use void (0) instead of #, for example:

The Code is as follows:


Click

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.