This article is a mirror article of machine translation, please click here to jump to the original article.

View: 9801|Reply: 0

[HTML/HTML5] Use of onclick and href in the A tag in HTML

[Copy link]
Posted on 11/5/2015 4:05:21 PM | | |

The linked onclick event is executed first, followed by the action under the href attribute (page jump, or javascrip{filter}t pseudo-link);
Assuming that there is both href and onclick in the link, if you want to prevent the action under the href property from being executed, onclick must get a false return value. If you don't believe me, you can comment out return false in the goGoogle function;
If the page is too long with a scroll bar and you want to perform an action via the linked onclick event. Its href property should be set to javascrip{filter}t:void(0); , not #, which prevents unwanted page bounces;
If you call a function with a return value in the linked href property, the content of the current page will be replaced by the return value of this function;
There is a difference when holding down the Shift key.
The problem I encountered today is that the parentNode cannot be accessed in the form of href in IE6.0.
Try not to use the javascrip{filter}t: protocol as the href attribute of A, which will not only cause unnecessary triggering of the window.onbeforeunload event, but also stop the animation gif in IE

Here is what I encountered:

If you don't set the href attribute, it will not respond to hover under IE6. Double-clicking will select the tag's parent container instead of this one-a tag (this is a problem in IE).
<a href="javascirpt:fn(this)"> <a> Suppose we have an fn method that needs to fetch this element, and the first method passes in this is null.

Therefore, the recommended way to write it is <a href="javascrip{filter}t:void(0)">




Previous:C# implements RSA encryption and decryption in detail
Next:jquery overrides the bootstrap-style alert/confirm message window
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com