Details about a tag click events in javascript

Source: Internet
Author: User
This article describes in detail the click events on the tag. It has good reference value. Let's take a look at it below. This article will detail the knowledge of click events on tag. It has good reference value. Let's take a look at it together with the small Editor.

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:

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.

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.

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.

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 a detailed description of the tag Click Event in javascript. For more information, see other related articles in the first PHP community!

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.