Method: 1. Use "#", the syntax is "a href="#""; 2. Use "javascript:", the syntax is "a href="javascript:void(0)""; 3. Use getElementById to get the a tag, and use "return false;" to cancel the jump.
The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.
<a href="www.baidu.com">百度</a>
1. Let’s do the simplest thing first. We can add the # sign directly to the html code, as follows:
<a href="#">百度</a> <!--点击时它会跳转到页面的最顶端了-->
2. Secondly, we The default event that blocks it is also the following:
<a href="javascript:void(0)">百度</a> <!--直接在里面添加一个阻止事件,当然直接是"javascript:"也是可以的,最好还是写全吧-->
3. There is also our js method to block it. We still give the a tag an id. We only need to do the following Operation:
<a id="Header1_HeaderTitle" href="www.baidu.com">百度</a>
let div1 = document.getElementById("Header1_HeaderTitle"); div1.onclick = function(){ return false; }
Recommended learning: css video tutorial
The above is the detailed content of How to prevent a tag from jumping in css. For more information, please follow other related articles on the PHP Chinese website!