检测中间鼠标单击事件jQuery [英] Detecting middle mouse click event jQuery

查看:110
本文介绍了检测中间鼠标单击事件jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户点击鼠标左键或中间键时,我想显示一个jQuery-UI对话框作为弹出窗口。它适用于左键单击(我获得警报框,之后的弹出窗口),但不适用于中间(既不是警报框也不弹出)。

I want to show a jQuery-UI dialog box as a popup when user clicks on left mouse button or the middle one. It works for left click (I get the alert box and after that the popup) but doesn't work for middle (neither alert box nor popup). What am I missing?

$('a.external').live('click', function(e){
  if( e.which <= 2 ) {
    e.preventDefault();
    alert ("inside if");
  }
  popUp.start(this);
});


推荐答案

使用 mousedown mouseup 而不是点击。 (除非您使用的是旧版本的jQuery)使用 .on()而不是 .live

Use mousedown or mouseup instead of click. And (unless you are using a very old version of jQuery) use .on() instead of .live():

$(document).on("mousedown", "a.external", function(e) {
   if( e.which <= 2 ) {
      e.preventDefault();
      alert ("inside if");
   }
   popUp.start(this);
});

...在理想情况下,您可以使用比<$ c更接近链接的父元素$ c> document 。

...where ideally you'd use a parent element much closer to the link than document.

演示: http:// jsfiddle.net/7S2SQ/

这篇关于检测中间鼠标单击事件jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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