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!