分享一段自己的学习笔记,希望大家多多指教:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>利用OnMousedown和OnContextmenu添加鼠标左中右键单击的处理</title>
<script type="text/javascript">
function Click(event)
{
GetMouseKey(event.button);
}
function GetMouseKey(button) {
if (button == 1) //鼠标中键
{
alert("单击了中键");
}
if (button == 4||button ==0) //event.button==1 鼠标左键
{
alert("单击了左键");
//处理代码
}
if (button == 2 ) // 测试在IE中按右键是2,在Maxthon2.0正式版中是0,IE中默认是0
{
alert("单击了右键");
//处理代码
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<!--oncontextmenu="return false"屏蔽快捷菜单-->
<div style=" margin:0 auto; width:200px; height:200px; background-color:Gray;" oncontextmenu="return false" onmousedown="Click(event)">
测试鼠标左键、右键、中键、左键右键组合键
</div>
</form>
</body>
</html>