当前位置:Gxlcms > JavaScript > js中各浏览器中鼠标按键值的差异_javascript技巧

js中各浏览器中鼠标按键值的差异_javascript技巧

时间:2021-07-01 10:21:17 帮助过:9人阅读

W3C DOM-Level-2 定义如下

W3C DOM 写道

During mouse events caused by the depression or release of a mouse button, button is used to indicate which mouse button changed state. The values for button range from zero to indicate the left button of the mouse, one to indicate the middle button if present, and two to indicate the right button. For mice configured for left handed use in which the button actions are reversed the values are instead read from right to left.

其描述的很明确,0,1,2分别代表左,中,右三个键。以下分别在mousedown,mouseup,click,dbclick中测试。

代码如下:

Test mousedown


Test mouseup


Test click


Test dbclick