Javascript: the role of void of 0 sample introduction

  • 2020-03-26 21:44:09
  • OfStack

Was in a page, if you want to do after a link click don't do anything, or do other things, in response to a click can set its properties href = "#", however, that there will be a problem, is when the page has the scroll bar, click later will return to the top of the page, or to set the anchor point, the user experience is bad.

The usual usage is:
 
<a href="javascript:void(0)"> Click here to see what it looks like </a> 

Nothing actually happens when you click here. Javascript :void(0); The form is a javascript pseudo-protocol that means that this link does not jump anywhere.

The main forms of using javascript:void(0) are as follows:
 
//Click on the link and do nothing
<a href="javascript:void(0);" >test</a> 
<a href="javascript:;" >test</a> 
<a href="####" >test</a> //Use 2 to 4 #'s, most of which are "####", some of which are "#all" and others

 
//After clicking a link, it responds to a user-defined click event
<a href="javascript:void(0)" onclick="doSomething()">test</a> 

Related articles: