2012-11-19 87 views
0

我和我的团队正试图解决这个问题。鼠标右键单击按钮应该执行左键单击按钮(jquery)的动作

有谁知道jQuery代码来执行左键单击按钮的操作时,鼠标右键点击

例如:说我右键点击,而不是打开一个弹出窗口中的链接,我需要它去链接的目的地。在其他需要我需要点击鼠标左键点击鼠标的动作。

尝试搜索网页,但没用。因此发布这是我最后的选择。

真的很感激任何帮助。

在此先感谢。

+0

这可能有帮助:http://stackoverflow.com/questions/1206203/how-to-distinguish-between-left-and-right-mouse-click-with-jquery – Th0rndike

回答

0

试试这个,例如(更新):

<html> 
<body oncontextmenu="return false;"> 
<a href="#">Test Link</a> 
<script src="jquery-1.8.2.min.js"></script> 
<script> 
$(document).ready(function() 
{ 
    $(document).mousedown(function(e) 
    { 

     if (e.button == 2) //right click 
     { 
     e.preventDefault(); 
     e.stopPropagation(); 
     e.stopImmediatePropagation(); 
     document.body.style.backgroundColor = "green"; 
     return false; 
     } 
     if (e.button == 0)//left click 
     { 
     e.preventDefault(); 
     e.stopPropagation(); 
     e.stopImmediatePropagation(); 
     document.body.style.backgroundColor = "blue"; 
     return false; 
     } 

    }); 
}); 
</script> 
</body> 
</html> 

如果你想阻止默认行为,改变背景颜色使用前e.preventDefault();e.stopPropagation(); e.stopImmediatePropagation();

+0

Gie me a min。请试试看。谢谢你 – jat

+0

哇。右键单击时,它停止弹出窗口。但是右键单击时没有将我带到URL。 – jat

+0

你需要实现你自己的点击链接行为(因为上面的代码取消了默认的行为) - 简单地把document.location.href ='URL here'; – bodi0

相关问题