开发者

Bind to right-click with jQuery?

I want to bind a function to a right 开发者_StackOverflowclick. Is this possible with jQuery UI?


though not listed on http://api.jquery.com/bind/, the 'contextmenu' event seems to work

$('.rightclickable').bind('contextmenu', function() {
    // right-click!
});


Not directly, but you can check which mouse button was pressed in a normal mousedown event handler, with the which property of the event object:

$("#someElem").mousedown(function(e) {
    if(e.which == 3) {
        //Right click!
    }
});

Here's a working example of the above.


Try

$(document).ready(function(){
    $(document).bind("contextmenu",function(e){
        //your
    });
});


$(document).bind('contextmenu',function(){
    return false;
});
$.fn.extend({
    "rightClick": function(fn){
        $(this).mousedown(function(e){
            if (3 == e.which) {
                fn();
            }
        });
    }
});
$(function(){
    $('selector').rightClick(function(){
        // defined your right click event here!
    });
}); 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜