如何更改鼠标左键单击和右键单击选项?

问题描述:

我有一些按顺序命名的HTML文件集。是否有可能将鼠标右键单击到下一个html页面,然后鼠标左键单击到之前的html页面,以及如何执行此操作?如何更改鼠标左键单击和右键单击选项?

+0

请参阅此链接 http://*.com/questions/1206203/how-to-distinguish-between-left-and-right-mouse-click-with-jquery – KrIsHnA 2013-02-26 04:55:39

这就是我们如何处理鼠标点击..

$('#element').mousedown(function(event) { 
    switch (event.which) { 
     case 1: 
      alert('Left mouse button pressed'); 
      //code to navigate to left page 
      break; 

     case 2: 
      alert('Right mouse button pressed'); 
      //code to navigate to right page 
      break; 
     default: 
      alert('Mouse is not good'); 
    } 
}); 
+0

信贷:http://*.com/questions/1206203/how-to-distinguish-between-left-and-right-mouse-click-with-jquery – AlphaMale 2013-02-26 04:58:39

+0

谢谢!知道了:) – 2013-02-26 06:16:51

+0

如果它的工作接受答案和upvote .. – sasi 2013-02-26 06:18:19

$(function(){ 
    $(document).mousedown(function(event) { 
    switch (event.which) { 
     case 1: 
      window.location.href = "http://*.com" // here url prev. page 
      break; 
     case 3: 
      window.location.href = "http://www.google.com" // here url next. page 
      break; 
     default: 
      break; 
    } 
    }); 
    }) 

而且不要忘了添加jQuery库。

+0

谢谢!完成它:) – 2013-02-26 06:16:04

你也可以用一些简单的Javascript来做到这一点。

<script type='text/javascript'> 
function right(e){ 
    //Write code to move you to next HTML page 
} 

<canvas style='width: 100px; height: 100px; border: 1px solid #000000;' oncontextmenu='right(event); return false;'> 
    //Everything between here's right click is overridden. 
</canvas> 
+0

谢谢!完成它:) – 2013-02-26 06:17:47

这是重写左右点击的传统方式。在代码中我也阻止了右键单击的事件传播,所以上下文菜单不会显示。

JSFiddle

window.onclick = leftClick 
window.oncontextmenu = function (event) { 
    event = event || window.event; 
    if (event.stopPropagation) 
     event.stopPropagation(); 

    rightClick(); 

    return false; 
} 

function leftClick(event) { 
    alert('left click'); 
    window.location.href = "http://www.google.com"; 
} 

function rightClick(event) { 
    alert('right click'); 
    window.location.href = "http://images.google.com"; 
} 
+0

谢谢!完成了:) – 2013-02-26 06:18:42