鼠标中键时点击Jquery? [英] Jquery alert when middle mouse button clicked?

查看:90
本文介绍了鼠标中键时点击Jquery?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

Jquery:检测是否点击了中间或右键单击,如果是这样做:

当我点击文本或任何dom元素时,如何显示点击鼠标中键的提示框?我想要使​​用jquery / javscript来区分中间鼠标和正常的右键单击。

How do I show alert box that says "middle mouse button clicked" when I click on text, or any dom element? I want to be able to differentiate between middle mouse and normal right click using jquery/javscript.

我没有提到这个:
Jquery:检测中间或右键的鼠标是否点击,如果是这样做:

并修改了js小提琴到:
http://jsfiddle.net/zAGLP/29/

and modified the js fiddle to this: http://jsfiddle.net/zAGLP/29/

但是正在寻找一个替代到live()函数。

But am seeking an alternative to "live()" function.

推荐答案

$(document).bind('mousedown', function(e) { 
   if( (e.which == 1) ) {
     alert("left button");
   }if( (e.which == 3) ) {
     alert("right button");
   }else if( (e.which == 2) ) {
      alert("middle button"); 
   }
   e.preventDefault();
}).bind('contextmenu', function(e){
 e.preventDefault();
});

这篇关于鼠标中键时点击Jquery?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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