Home >Web Front-end >HTML Tutorial >Comparative introduction to a tag href attribute and onclick event_HTML/Xhtml_Web page production
First of all, let’s talk about the execution order of href attribute and onclick event. When the mouse clicks on the a tag, the onclick event will be executed first, and then the action under the href attribute (page jump, or javascript pseudo link), if you don’t want to To execute the action 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 standard writing methods in the href attribute
"void is an operator in Javascript that specifies to evaluate an expression but does not return a value.
void operator usage format is as follows:
1. javascript:void (expression)
2. javascript:void expression
expression is a Javascript standard expression to be evaluated. The parentheses outside the expression are optional, but are a good practice to write. (Implementation version Navigator 3.0)
You can specify a hyperlink using the void operator. The expression will be evaluated but nothing will be loaded into the current document. ”
href=# contains a location information. The default anchor is #top, which is the top of the web page, while javascript:void(0) only represents a dead link without any information. So it’s best to use void(0)
when calling a scripthref generally points to a URL address, and can also call javascript, such as href="javascript:xxx();", the document recommends writing like this: xx, but this method sometimes causes strange problems in complex environments. Try not to use javascript: protocol as the href attribute of A. This will not only cause unnecessary triggering of window. The onbeforeunload event will stop the playback of animated gif images in IE.