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
If I want to make the form non-input-capable, I se...
Preface This article describes two situations I h...
Table of contents introduction 1. Case Overview 2...
Beginners who are exposed to HTML learn some HTML...
Overview When a 500 or 502 error occurs during ac...
Install the nvidia graphics card driver under Ubu...
Today, when I searched for a page on Baidu, becaus...
By default, PHP on CentOS 7 runs as apache or nob...
CSS Styles html,body{ width: 100%; height: 100%; ...
This article example shares the specific code of ...
Today, let's introduce several common text pr...
1. Download Download mysql-5.7.19-linux-glibc2.12...
Table of contents 1. Brief Introduction 2. setInt...
Note: This article has been translated by someone ...
Method 1: hostnamectl modification Step 1 Check t...