如何更改鼠标左键单击和右键单击选项?
答
这就是我们如何处理鼠标点击..
$('#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');
}
});
答
$(function(){
$(document).mousedown(function(event) {
switch (event.which) {
case 1:
window.location.href = "http://stackoverflow.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
答
这是重写左右点击的传统方式。在代码中我也阻止了右键单击的事件传播,所以上下文菜单不会显示。
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
请参阅此链接 http://stackoverflow.com/questions/1206203/how-to-distinguish-between-left-and-right-mouse-click-with-jquery – KrIsHnA 2013-02-26 04:55:39