如何使链接不可点击使用CSS或jquery? [英] How to make link unclickable using CSS or jquery?
本文介绍了如何使链接不可点击使用CSS或jquery?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下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 =#
As you can see when I click on "Link" then it takes me to "test.php" page. I want this "Link" to be unclickable like you place "#" for e.g. href="#"
可以使用CSS或Jquery吗?不能使用Javascript的 document.getElementById ,因为没有为此元素定义ID。
Is it possible to do this using CSS or Jquery? Can't use Javascript's document.getElementById because there is no ID defined for this element.
推荐答案
不同的选项:
$('a[href="test.php"]').click(function(){
return false;
});
或
$("static dynamic-children a.menu-item").click(function(){
return false;
});
您也可以使用 event.preventDefault() ,以防止链接的默认/预期行为。使用方式:
You can also use event.preventDefault() which prevents the default/expected behaviour of a link. Use like:
$("static dynamic-children a.menu-item").click(function(event){
event.preventDefault();
});
这篇关于如何使链接不可点击使用CSS或jquery?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文