javascript判断触发事件event的鼠标按钮

<html>
<head>
<script type="text/javascript">
function whichButton(event)
{
var btnNum = event.button;
if (btnNum==2)
  {
  alert("您点击了鼠标左键!")
  }
else if(btnNum==0)
  {
  alert("您点击了鼠标右键!")
  }
else if(btnNum==1)
  {
  alert("您点击了鼠标中键!");
  }
else
  {
  alert("您点击了" + btnNum+ "号键,我不能确定它的名称。");
  }
}
</script>
</head>

<body onmousedown="whichButton(event)">
<p>请在文档中点击鼠标。一个消息框会提示出您点击了哪个鼠标按键。</p>
</body>

</html>

from:http://www.w3school.com.cn/tiy/t.asp?f=hdom_event_button

原文地址:https://www.cnblogs.com/lidabo/p/2616582.html