This question already has answers here:
How to disable HTML links
(15 个回答)
7年前关闭。
我有以下 HTML。
正如您所看到的,当我单击“链接”时,它会将我带到“test.php”页面。我希望这个“链接”是不可点击的,就像你放置“#”一样,例如href="#"
是否可以使用 CSS 或 Jquery 来做到这一点?不能使用 Javascript 的 document.getElementById 因为没有为这个元素定义 ID。
或者
您还可以使用 event.preventDefault() 来防止链接的默认/预期行为。像这样使用:
(15 个回答)
7年前关闭。
我有以下 HTML。
<ul class="static">
<li class="static dynamic-children">
<a class="static dynamic-children menu-item" href="test.php" tabindex="0">
<span class="additional-background">
<span class="menu-item-text">Link</span>
</span>
</a>
<ul class="dynamic">
</ul>
</li>
</ul>
正如您所看到的,当我单击“链接”时,它会将我带到“test.php”页面。我希望这个“链接”是不可点击的,就像你放置“#”一样,例如href="#"
是否可以使用 CSS 或 Jquery 来做到这一点?不能使用 Javascript 的 document.getElementById 因为没有为这个元素定义 ID。
最佳答案
不同的选择:
$('a[href="test.php"]').click(function(){
return false;
});
或者
$("static dynamic-children a.menu-item").click(function(){
return false;
});
您还可以使用 event.preventDefault() 来防止链接的默认/预期行为。像这样使用:
$("static dynamic-children a.menu-item").click(function(event){
event.preventDefault();
});
关于javascript - 如何使用 CSS 或 jquery 使链接不可点击?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20728292/