我有一些按顺序命名的HTML文件集。是否可以将鼠标右键单击指定到下一个html页面并鼠标左键单击到上一个html页面以及如何执行此操作?
答案 0 :(得分:1)
这就是我们处理鼠标点击的方式..
$('#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');
}
});
答案 1 :(得分:0)
$(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库。
答案 2 :(得分:0)
您也可以使用一些简单的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>
答案 3 :(得分:0)
这是覆盖左右点击的传统方式。在代码中,我阻止了右键单击事件的传播,因此上下文菜单不会显示。
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";
}