Detecting middle mouse click event jQuery

前端 未结 2 950
忘了有多久
忘了有多久 2020-12-20 16:04

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 pop

2条回答
  •  渐次进展
    2020-12-20 16:09

    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);
    });
    

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

    Demo: http://jsfiddle.net/7S2SQ/

提交回复
热议问题