How to distinguish between left and right mouse click with jQuery

后端 未结 17 2706
独厮守ぢ
独厮守ぢ 2020-11-21 22:36

How do you obtain the clicked mouse button using jQuery?

$(\'div\').bind(\'click\', function(){
    alert(\'clicked\');
});

this is trigger

17条回答
  •  失恋的感觉
    2020-11-21 23:03

    there is also a way, to do it without JQuery!

    check out this:

    document.addEventListener("mousedown", function(evt) {
        switch(evt.buttons) {
          case 1: // left mouse
          case 2: // right mouse
          case 3: // middle mouse <- I didn't tested that, I just got a touchpad
        }
    });
    

提交回复
热议问题