First of all, let’s talk about the execution order of the href attribute and onclick event. When the mouse clicks on the a tag, the onclick event will be executed first, and then the actions under the href attribute (page jump, or javascript pseudo-link). If you do not want to execute the actions under the href attribute, onclick needs to return false. Generally, onclick=xxx();return false is written like this.
How to execute javascript code expressions and specification writing methods in the href attribute
In Javascript void is an operator that specifies that an expression is to be evaluated but does not return a value.
The usage format of the void operator is as follows:1. javascript:void (expression)
2. javascript:void expression
expression is a Javascript standard expression to be calculated. The brackets on the outside of the expression are selected, but writing them is a good habit. (Implement version Navigator 3.0)
You specify the hyperlink by using the void operator. The expression will be calculated but nothing is loaded in the current document.
href=# contains a location information. The default anchor is #top, that is, the upper end of the web page, while javascript:void(0) only represents a dead link and has no information. So it is best to use void(0) when calling scripts
href generally points to a URL address, and you can also call javascript, such as href=javascript:xxx();. The document recommends writing this as follows: <a href=javascript:void(0) onclick=xxx();>xx</a>, but this method sometimes causes strange problems in complex environments. Try not to use the javascript: protocol as A's href attribute, which will not only cause unnecessary triggering of the window.onbeforeunload event, but also stop playing gif animation images in IE.