Js a tag Click Event, jsa tag event

Source: Internet
Author: User

Js a tag Click Event, jsa tag event

When processing click events on tag a, we find that even if the content in href = "" is empty, the effect of click events is not obvious. How can this problem be solved? There are several common solutions:

1.A href = "javascript: void (0);" rel = "external nofollow" onclick = "method ()"

This method is the most commonly used method and the most comprehensive method. The onclick method is used to execute js functions, while void is an operator. void (0) returns undefined and the address does not jump. In addition, this method does not directly expose the js method to the browser's status bar like the first method.

2.A href = "javascript:;" rel = "external nofollow" onclick = "method ()"

This method is similar to the two methods. The difference is that an empty js code is executed.

3.A href = "#" rel = "external nofollow" rel = "external nofollow" onclick = "method ()"

This method is also a common code on the Internet. # is a built-in label method, which represents the role of top. Therefore, after clicking this method, the page is returned to the top of the page.

4.A href = "#" rel = "external nofollow" rel = "external nofollow" onclick = "method (); return false ;"

In this way, click "return false" after the js function is executed, and the default behavior of the event is blocked. The page does not jump and is still in the current position after execution.

The above is all the content of this article. I hope this article will help you in your study or work. I also hope to provide more support to the customer's home!

Related Article

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.