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!