Introduction to void keywordFirst of all, the void keyword is a very important keyword in JavaScript. This operator specifies that an expression is to be calculated or run, but no value is returned. Syntax format:
Example 1When clicking the hyperlink, nothing happens <!-- 1. When the user links, void(0) is calculated as 0, and the user's click will not have any effect--> <a href="javascript:void(0);" rel="external nofollow" rel="external nofollow" >Click here and nothing will happen</a><br> Example 2Execute the code in the void operator <!-- 2. Execute the code in the void() operator --> <a href="javascript:void(alert('You're really obedient!!! Hahaha!!!'))" rel="external nofollow" >Click me to pop up a warning box!!!</a><br> <a href="javascript:void(console.log('You're really obedient!!! Hahaha!!!'))" rel="external nofollow" >Click me to output to the console!!!</a><br> Example 3Computing Arithmetic with Void Operators html: <button type="button">Click me</button> js: <script type="text/javascript"> document.querySelector('button').addEventListener('click', function () { var a, b, c, d; a = void(b = 2, c = 3); console.log('a => ' + a); console.log('b => ' + b); console.log('c => ' + c); console.log('d => ' + d); }); </script> Console output: Obviously, 2 is assigned to a, 3 is assigned to b, and a is just defined like d, so it is undefined. # Difference from javascript:void(0):#You can jump to the destination with the set id javascript:void(0) stays where it is, motionless, we call it a "dead link" As in the following example: <a href="javascript:void(0);" rel="external nofollow" rel="external nofollow" >You can click, I won’t move anyway, hehehe! ! ! </a><br> <a href="#destination" rel="external nofollow" >Click me to jump</a> <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> <h2 id="destination">Destination</h2>
This concludes this article about the meaning and usage examples of javascript:void(0). I hope it will be helpful for everyone’s study, and I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Sharing of research experience on using characters instead of rounded corners and sharp corners
>>: Detailed explanation of MYSQL stored procedure comments
1. Enter the host machine of the docker container...
This article example shares the specific code of ...
Overview Nginx can use variables to simplify conf...
I recently encountered a problem. The emoticons o...
Table of contents 1. ChildNodes attribute travers...
Preface At first, I wanted to use wget to downloa...
Table of contents Overview 1. Creation of Refs ob...
This article example shares the specific code of ...
Table of contents What is the Linux system that w...
MySQL is an open source small relational database...
cause The way to import external files into a min...
Table of contents 1. Event delegation Event Bubbl...
1. addtime() Add the specified number of seconds ...
Table of contents No switch, no complex code bloc...
In a front-end technology group before, a group m...