button 事件属性可返回一个整数,指示当事件被触发时哪个鼠标按键被点击。
event.button=0|1|2
| 参数 | 描述 | 
|---|---|
| 0 | 规定鼠标左键。 | 
| 1 | 规定鼠标中键。 | 
| 2 | 规定鼠标右键。 | 
Internet Explorer 拥有不同的参数:
| 参数 | 描述 | 
|---|---|
| 1 | 规定鼠标左键。 | 
| 4 | 规定鼠标中键。 | 
| 2 | 规定鼠标右键。 | 
注释:对于惯用左手的鼠标配置,上面的参数是颠倒的。
提示:Mozilla 的 Ctrl–Click 参数是 2 (等价于右击)。
The following example alerts which mouse button was clicked:
<html>
<head>
<script type="text/javascript">
function whichButton(event)
  {
    if (event.button==2)
      {
      alert("You clicked the right mouse button!")
      }
    else
      {
      alert("You clicked the left mouse button!")
      }
  }
</script>
</head>
<body onmousedown="whichButton(event)">
	
<p>Click in the document. An alert box will 
alert which mouse button you clicked.</p>
</body>
</html>