指针事件禁用锚标记 [英] Pointer Event Disable anchor tag

查看:28
本文介绍了指针事件禁用锚标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须禁用 li 上的链接,但不应禁用所有事件,只需禁用该链接,它将是可点击的,因此我可以在其上使用隐藏和显示菜单功能

I have to disable the link on an li but it should not be disabled all events just disable the link and it will be clickable so i can use hide and show menu function on it

#menu-item-747 {
  pointer-events: none;
  cursor: default;
}

我在这个 li 上使用了 jQuery 来隐藏和显示其他 li 并且在这个 li 上一个链接用于另一个页面,我只是想禁用链接,它仍然可以点击运行 jQuery 切换.

I have used jQuery on this li to hide and show other li and on this li a link is used for another page, I just want to disable link and it will be still clickable to run jQuery toggle.

推荐答案

要禁用链接,只需执行

$('#menu-item-747 a').click(function(e){
     e.preventDefault();
});

这不会阻止其他操作,只会阻止默认链接元素之一(即跟随链接).

This won't prevent other actions, just the default one of the link element (i.e. following the link).

这篇关于指针事件禁用锚标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆