I am looking for some java script right click menu using both key board and m开发者_如何转开发ouse.
have any one seen a good plug in?
Using jQuery, to detect the right click you can do:
$('body').bind('mousedown', function(event) {
if (event.which == 3) {
// Create menu here
}
});
To detect a certain key:
$('body').bind('keydown', function(event) {
if (event.which == //some key code, like 70) {
// Create menu here
}
});
Check out the oncontextmenu
event, which is supported by every major browser except Opera. This will fire for the right-click and keyboard context menu if you want to display your own:
$("#myDiv").bind("contextmenu", function () {
$("#menu").show();
return false;
});
Note that Firefox users can expressly disable context menu overriding. For Opera, you'd have to bind to the click
event and necessary key combinations (which may vary between operating systems).
have a look at these plugins...
right click plugin
精彩评论