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. Replace your .js library file address with the...
This article uses examples to describe how to cre...
Table of contents 1 Test Environment 1.1 Server H...
The async_hooks module is an experimental API off...
Preface When I was studying the front end before,...
Unlike other types of design, web design has been ...
The local environment is Windows 10 + WSL2 (Ubunt...
With the increasing number of open platforms, the ...
Configuring Alibaba Cloud Docker Container Servic...
For detailed documentation on installing the comp...
In Node.js, a .js file is a complete scope (modul...
If you want to solve the slow problem once and fo...
Learning Linux commands is the biggest obstacle f...
This article example shares the specific code of ...
yum or rpm? The yum installation method is very c...