We used to have click events in a tag:
1. A href= "Javascript:js_method ();"
This is a common method on our platform, but this method is prone to problems when passing parameters such as this, and JavaScript: The protocol as the HREF attribute of a will not only cause unnecessary triggering of the Window.onbeforeunload event, but will also stop the animated GIF image from playing in IE. The standard is not recommended to execute JavaScript statements in href
2. A href= "javascript:void (0);" onclick= "Js_method ()"
This method is the most common method for many websites , but also the most comprehensive method, the OnClick method is responsible for executing the JS function, and void is an operator, void (0) returns undefined, the address does not occur jump. And this method does not directly expose the JS method to the browser's status bar, as in the first method.
3.a href= "javascript:;" onclick= "Js_method ()"
This method is similar to that of 2, except that it executes an empty JS code.
4.a href= "#" onclick= "Js_method ()"
This method is also very common online code, #是标签内置的一个方法, representing the role of top. So use this method to return to the top of the page after clicking on the page.
5.a href= "#" onclick= "Js_method (); return false;"
This method clicks Execute JS function and return false, the page does not jump, after execution or in the current position of the page.
I looked at Taobao's homepage, they adopted the 2nd method, and Alibaba's homepage is the 1th method, and the difference is that each href JavaScript method is surrounded by a try, catch.
Synthesizing the above, the most appropriate method of invoking the JS function in a is recommended:
a href= "javascript:void (0);" onclick= "Js_method ()"
A href= "javascript:;" Onclick= "Js_method ()"
A href= "#" onclick= "Js_method (); return false;"
How to implement various click (onclick) events in the A label