[JS] Realize that a label does not jump when clicked

1. Use empty code

  • This method is similar to the second, the difference is that an empty js code is executed.
<a href="javascript:;">不能跳到百度</a>

2. Using pseudo-protocols

  • void is an operator, void(0) returns undefined, the address does not jump
<a href="javascript:void(0);" >不能跳到百度</a>

3. Return false

  • html writing
<a href="http://www.baidu.com" onclick="return false" >不能跳到百度</a>
  • jsx writing
<a 
	href="http://www.baidu.com" 
	onclick={
    
    ()=>{
    
    
		console.log('函数里面可以正常执行函数操作')
		return false;
	}} 
>
不能跳到百度
</a>

Guess you like

Origin blog.csdn.net/qq_45677671/article/details/131012151