A tag to prevent page jumps

javascript: is a pseudo-protocol, other pseudo-protocols include mail: tel: file: and so on.

<a id="jsPswEdit" class="set-item" href="javascript:;">修改密码</a>

javascript: means to execute a piece of JavaScript code when the <a> default action is triggered, and javascript :; means to execute nothing, so that when you click <a>, nothing happens.

Generally in this case, an event callback will be bound to <a> to execute the business, such as:

document.getElementById('jsPswEdit').addEventListener('click', function(e) {
  e.preventDefault();
  // 当<a>触发click时,处理业务
}, false);

href = "javascript :;" is the default behavior of removing the a tag, which is the same as href = "javascript: void (0)"

void is an operator in JavaScript, and void (0) means doing nothing.

Other ways to prevent page jumps:

1、<a href="#" >test</a>;

Click the link, the page scrolls to the top of the page by default, but you can add οnclick = "return false" to prevent scrolling to the top of the page.

2、<a href="####" >test</a>;

Use 2 to 4 #, mostly see "####", there are other "#all" and so on. A meaningless label is specified without any processing.

3、<a href="javascript:void(0);" >test</a>; 

javascript: void (0) indicates a dead link and executes an empty event.

Published 14 original articles · Like 4 · Visitors 8816

Guess you like

Origin blog.csdn.net/weixin_41575159/article/details/93191538