在jquery中,如何使鼠标的右键单击具有与左键单击相同的行为 [英] in jquery, how to make the right click of the mouse have the same behavior of left click
本文介绍了在jquery中,如何使鼠标的右键单击具有与左键单击相同的行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要实现的是:当我右键单击一个链接时,它还会跳到另一个页面,如单击鼠标左键.怎么做?非常感谢.
what i want to realize is : when I right click a link , it also jump to another page like left click. how to do it? thanks very much.
推荐答案
There is a plugin that will handle a lot of this for you: http://abeautifulsite.net/blog/2008/05/jquery-right-click-plugin/
或者如果您想自己滚动:
Or if you wanted to roll your own:
检出有关event.which的文档: http://api.jquery.com/event.哪个/
Check out the docs for event.which: http://api.jquery.com/event.which/
您可以检测到单击了哪个鼠标按钮:
You can detect which mouse button was clicked:
$('.clicky').mousedown(function(event) {
switch (event.which) {
case 1:
alert('Left mouse button pressed');
break;
case 2:
alert('Middle mouse button pressed');
break;
case 3:
alert('Right mouse button pressed');
// you would want to prevent default behavior and trigger a click
event.preventDefault();
$(this).trigger('click');
break;
default:
alert('You have a strange mouse');
}
});
这篇关于在jquery中,如何使鼠标的右键单击具有与左键单击相同的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文