如何禁用鼠标滚轮单击按钮? [英] How to Disable the Mouse wheel click Button?

查看:779
本文介绍了如何禁用鼠标滚轮单击按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试找到一种方法来禁用鼠标滚轮按钮的默认操作,即在新标签页中打开链接。

I'm trying to find a way of disabling the default action of the mouse wheel button which is to open the link in a new tab.

这是可能的吗? ?

推荐答案

绑定专门检查中间点击的通用点击事件处理程序。在该事件处理程序中,调用 e.preventDefault()

Bind a generic click event handler that specifically checks for middle clicks. Within that event handler, call e.preventDefault():

$("#foo").on('click', function(e) { 
   if( e.which == 2 ) {
      e.preventDefault();
   }
});

请注意,并非所有浏览器都支持阻止此默认操作。对我来说,它只适用于Chrome。 Firefox,Opera和IE9都不会通过鼠标中键点击提升点击事件。他们确实提高了鼠标和mousedown。

Note that not all browsers support preventing this default action. For me, it only works in Chrome. Firefox, Opera and IE9 all do not raise the click event with middle mouse click. They do raise mouseup and mousedown.

这篇关于如何禁用鼠标滚轮单击按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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