The difference between using JavaScript in the href and onclick of a label
The ⒈ link onclick event is executed first, followed by the action under the HREF attribute (page jump, or JavaScript pseudo link);
⒉ assume that there is both href and onclick in the link, and if you want the action under the HREF attribute to not execute, the onclick must get a false return value;
⒊ If the page has a scroll bar too long and you want to perform the action through the linked onclick event. Its href attribute should be set to Javascript:void (0) instead of #, which prevents unnecessary page runout;
⒋ If you call a function with a return value in the href attribute of the link, the contents of the current page will be replaced by the return value of the function;
⒌ is different when you hold down the SHIFT key.
⒍ IE6.0 in the form of an href to parentnode. Try not to use JavaScript: protocol as the HREF attribute of a, this will not only cause unnecessary trigger window.onbeforeunload event, in IE will make GIF animated pictures stop playing. It took a lot of time on this.
(Under IE6)
<a href= "javascript:void (0);" onclick= "Javascript:modifypassword ();" ></a>
This kind of writing IE6 the following URL although requested backstage, but no movement at the front desk,
The correct wording should be
<a href= "javascript:void (0);" onclick= "Javascript:modifypassword (); return false;" ></a>
A few examples of personal collections for you to learn:
1:<a href= "#" ></a>
2:<a href= "javascript:void (0)" ></a>
3:<a href= "javascript:void (null)" ></a>
4:<a href= "#" onclick= "return false" ></a>
5:<span style= "Cursor:hand" ></span> (as if not shown in FF)---------------------------------------------------- ---------------------------
Careful with javascript:void (0) today when the test, obviously the program has been executed, and the final result is correct, but the page is not refreshed.
In FireFox2.0 and IE7 under the test, the result is normal, IE6 but not refreshing. After careful investigation, found that the page link is <a href= "javascript:void (0)" onclick= "Xxx_func ();" ....> test </a> The problem is on this void (0)!
Let's take a look at the meaning of Void (0) in javascript: JavaScript void is an operator that specifies that you want to evaluate an expression but not return a value. The
void operator usage format is as follows:
1 javascript:void (e-xpression)
2. Javascript:void e-xpression
E-xpression is a calculated A JavaScript-standard expression. The parentheses outside the expression are optional, but writing is a good habit. We can use the void operator to specify a hyperlink. The expression is evaluated but does not load any content in the current document. Surface code creates a hyperlink that will not happen when the user clicks on it. When the user clicks on the link, void (0) evaluates to 0, but there is no effect on JavaScript. <a href= "javascript:void (0)" > Click here Nothing happens </a> that is, you can use void (0) to perform some processing, but not to refresh the page as a whole. But if you need to refresh the page, then be careful. In fact, we can use <a href= "javascript:void (Document.form.submit)", this sentence will be a submit operation. What is the case with void (0) More? No refresh, of course, Ajax, look at the AJAX Web page, you will generally see a lot of void (0),: So in the use of void (0) before, it is best to think about whether the page needs to be overall refreshed.