How to distinguish between left and right mouse click with jQuery

后端 未结 17 2702
独厮守ぢ
独厮守ぢ 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:08

    $.event.special.rightclick = {
        bindType: "contextmenu",
        delegateType: "contextmenu"
    };
    
    $(document).on("rightclick", "div", function() {
        console.log("hello");
        return false;
    });
    

    http://jsfiddle.net/SRX3y/8/

提交回复
热议问题