Reprinted from: http://gocom.primeton.com/blog21307_27051.htm
I used to write <A> the href and onclick have been very casual, and then a few questions, and then began to pay attention to this problem:
In JavaScript, Void is an operator that specifies that an expression is evaluated but does not return a value.
The void operator uses the following format:
1. javascript:void (expression)
2. Javascript:void expression
Expression is a standard of Javascript to evaluate. Parentheses on the outside of the expression are optional, but writing is a good habit. (Implementation version Navigator 3.0)
You use the void operator to specify a hyperlink. The expression is evaluated but does not load any content at the current document.
The following code creates a hyperlink that will not happen to the user in the future. void (0) evaluates to 0 when the user links, but does not have any effect on Javascript.
<a href= "javascript:void (0)" > single here Nothing will happen </A>
The following code creates a hyperlink that submits the form when the user orders it.
<a href= "Javascript:void (Document.form.submit ())" >
The following code executes the SUBGO () function,
<a href= "javascript:void (0)" onclick= "Subgo ()" > Point me </a>
Here, javascript:void (0), does not have a substantial effect, it is just a dead link, the function that executes is subgo ().
<a href= "#" onclick= "Subgo ()" > Point me </a> with <a href= "javascript:void (0)" onclick= "Subgo ()" > Point me </a> Difference.
In fact #包含了一个位置信息默认的锚是 #top is the upper end of the page, and javascript:void (0) simply represents a dead link with no information. So it's best to use void when calling scripts (0)
href generally refers to a URL address, you can also call JavaScript, such as href= "javascript:xxx ();", recommended in the documentation: <a href= "javascript:void (0)" onclick= "xxx ();" >xx</a> But this approach sometimes creates strange problems in complex environments, try not to use JavaScript: protocol as the href attribute of a , This will not only lead to unnecessary triggering of window.onbeforeunload events, in IE will make GIF animated pictures stop playing.
We know that the onclick event of the link is executed first, followed by the action under the HREF attribute (page jump, or JavaScript pseudo-link), and if you do not want to perform the action under the HREF attribute, the onclick needs to return false, which is generally written onclick= " xxx (); return false; ".
[Reprint] The HREF and onclick of label A