The VOID operator evaluates the given expression and returns directly to the undefined
The void operator is usually used only to get The original value of the undefined, typically using void (0)(equivalent to void 0). In the above case, you can also use the global variable undefined instead (assuming it is still the default value).
<script> Console.log (void (Console.log ("OK"))); </script> |
The result of this code is :
Ok
Undefined
Generally I personally call javascript:void (0) dead link
and Javasccript:; is an empty link, in fact, he is also a direct return of the undefined, and the former is calculated after the return undefined
Personal habits Use the former, as if the feeling behind the faster point, I feel at the front of it doesn't matter
-----------------------------------------------------------------------
When the user clicks on a Javascript:uri, the browser evaluates the code after the colon and then displays the result of the evaluation on the page, which is basically a blank space, which is usually not what we want. The browser does not do this stupid thing only when the evaluation result of this code is undefined, so we often use the void operator to implement this requirement
Look at the code :
<a href= "javascript:void (0);" > This link will not do anything after clicking, if it is removed void (), After clicking the entire page will be replaced with a character 0. </a> <a href= "javascript:void (document.body.style.backgroundcolor= ' green '); > Clicking on this link will turn the background of the page to green. </a> |
Reference content :
https://segmentfault.com/q/1010000002435291
Https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Operators/void
http://www.koikikukan.com/archives/2015/03/11-002222.php
A little extra : about <a href= "#" ></a>
#包含了一个位置信息
The default anchor is #top the top of the page
If you want to complete the equivalent of the right side of the wording, I provide three ways to reference
<a href= "#" onclick= "return false;" >href</a>
<a href="javascript: return false;" onclick=" js method called ">href</a>
<a href= "# #" > here is an empty link, not tested </a>
There are other ways : The code is right here.
<script>
function foo () {
// ...
}
</script>
<a href= "http://user-domain/" onclick= "foo (); return false" >test</a>
-----The second way
<script src= "Http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js" ></script>
<script>
$ (function () {
$ (' #test '). Click (function (e) {
E.preventdefault ();
return false;
});
});
</script>
<a href= "http://user-domain/" id= "test" >test</a>
What is the difference between "javascript:;" and "javascript:void (0)"?