3

I want control middle mouse button, I mean when user left clicked of middle clicked or right clicked on my link I should show fancybox.

so I use this code :

$(".reg").live("mousedown", function(e) {
    if ((e.which == 1) || (e.which == 2) || (e.which == 3)) {
        $.fancybox({
            href : 'register.php'
        });
    }
    e.preventDefault();
    return false;
});

But on this code just left click will work.

4

1 回答 1

-1

请尝试这里写的解决方案http://www.stackoverflow.com/questions/4007482/jquery-detect-if-middle-or-right-mouse-button-is-clicked-if-so-do-this

可能对你有用。

例子:

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

这是小提琴http://jsfiddle.net/p49nF/。我在 Firefox 19 和 Chrome 25 中对其进行了测试,它对我来说运行良好。

于 2013-03-10T16:54:55.267 回答