First of all, let's talk about the execution order of the href attribute and the onclick event. When the mouse clicks 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 execute the action under the href attribute, onclick needs to return false, which is usually written like onclick="xxx();return false. How to execute javascript code expressions and standard writing in href attributes "In JavaScript, void is an operator that specifies that an expression is to be evaluated but no value is to be returned. The void operator usage format is as follows: 1. javascript: void (expression) expression is a JavaScript-standard expression to be evaluated. The parentheses around the expression are optional, but it is good practice to write them. (Implemented in Navigator 3.0) You can specify hyperlinks 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 indicates a dead link without any information. So it is best to use void(0) when calling the script href usually points to a URL address, and can also call javascript, such as href="javascript:xxx();". The document recommends writing it like this: <a href="javascript:void(0)" onclick="xxx();">xx</a>, but this method sometimes causes strange problems in complex environments. Try not to use javascript: protocol as A's href attribute, which will not only lead to unnecessary triggering of window.onbeforeunload event, but also stop playing gif animation pictures in IE. |
<<: Some conclusions on the design of portal website focus pictures
>>: Detailed process of deploying Docker to WSL2 in IDEA
Intersection Selector The intersection selector i...
Preface When a Linux is fully set up, you can use...
title XML/HTML CodeCopy content to clipboard <...
1. Check whether event is enabled show variables ...
MySQL consistency log What happens to uncommitted...
<br />The page uses UTF8 encoding, and the h...
Use native js to implement a simple calculator (w...
Because I have been tinkering with Linux recently...
illustrate DML (Data Manipulation Language) refer...
Preface I just bought a new VPS. The data disk of...
environment Host IP 192.168.0.9 Docker version 19...
Preface mysqlslap is a diagnostic program designe...
During normal project development, if the MySQL v...
Table of contents 1 Node.js method of sending ema...
Table of contents 1. Auxiliary functions 2. Examp...