JS to click the link to cancel the jump effect

  • 2020-03-30 01:29:30
  • OfStack


<!DOCTYPE html> 
<html> 
<head> 
<meta charset="utf-8"> 
<meta name="author" content="//www.jb51.net/" /> 
<title> The home of the script </title> 
<script type="text/javascript"> 
window.onload=function() 
{ 
  var olink=document.getElementById("link"); 
  olink.onclick=function() 
  { 
    if(confirm(" Whether or not to delete ?")){alert(" File deleted ");} 
    return false; 
  } 
} 
</script> 
</head> 
<body> 
<a href="#" id="link"> Whether or not to delete </a> 
</body> 
</html>

The above code implements our requirements, and the link will only be used as a normal button. Here, we mainly use the return false statement in the click event of the link, which can cancel the default action of the link


Related articles: