如何用jQuery区分鼠标左键和右键如何使用jQuery获得单击的鼠标按钮?$('div').bind('click', function(){
alert('clicked');});这是由右击和左键触发的,有什么方法可以捕捉鼠标右键点击呢?如果像下面这样的东西存在,我会很高兴的:$('div').bind('rightclick', function(){
alert('right mouse button is pressed');});
3 回答
倚天杖
TA贡献1828条经验 获得超3个赞
event.which
event.keyCode
event.charCode
event.which
event.which
$('#element').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.'); break; default: alert('You have a strange Mouse!'); }});
米琪卡哇伊
TA贡献1998条经验 获得超6个赞
which
/* 1 = Left mouse button 2 = Centre mouse button 3 = Right mouse button */$([selector]).mousedown(function(e) { if (e.which === 3) { /* Right mouse button was clicked! */ }});
添加回答
举报
0/150
提交
取消