button 事件属性可返回一个整数,指示当事件被触发时哪个鼠标按键被点击。
</>code
- 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:
</>code
- <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>
如对本文有疑问,请提交到交流论坛,广大热心网友会为你解答!! 点击进入论坛
Powered by 365建站网 RSS地图 HTML地图
copyright © 2013-2024 版权所有 鄂ICP备17013400号