MouseEvent.buttons

这篇翻译不完整。请帮忙从英语翻译这篇文章

只读属性MouseEvent.buttons指示事件触发时哪些鼠标按键被按下。
 

每一个按键都用一个给定的数(见下文)表示。如果同时多个按键被按下,buttons 的值为各键对应值做与计算(|)后的值。例如,如果右键(2)和滚轮键(4)被同时按下,buttons 的值为 2 | 4 = 6。

注意:属性 MouseEvent.button 和 MouseEvent.buttons 是不同的。MouseEvent.buttons 可指示任意鼠标事件中鼠标的按键情况,而 MouseEvent.button 只能保证在由按下和释放一个或多个按键时触发的事件中获得正确的值。

语法

var buttonPressed = instanceOfMouseEvent.buttons

返回值

一个数字,用来标识鼠标按下的一个或者多个按键。如果按下的键为多个,则值等于所有按键对应数值进行或(|)运算的结果。

  • : 没有按键或者是没有初始化
  • : 鼠标左键
  • : 鼠标右键
  • : 鼠标滚轮或者是中键
  • : 第四按键 (通常是“浏览器后退”按键)
  • 16 : 第五按键 (通常是“浏览器前进”)

Specifications

Specification Status Comment
Document Object Model (DOM) Level 3 Events Specification
MouseEvent.buttons
Obsolete Initial definition

Browser compatibility

Feature Edge Firefox (Gecko) Chrome Internet Explorer Opera Safari
Basic support (Yes) (Yes)[1] 43[2] 9 (Yes) 未实现
Feature Edge Firefox Mobile (Gecko) Android IE Mobile Opera Mobile Safari Mobile
Basic support (Yes) ? ? ? ? ?

[1] Gecko supports the buttons attribute on Windows, Linux (GTK), and Mac OS with the following restrictions:

  • On Windows, if you install a mouse driver, and its utility software allows you to customize button actions (e.g., IntelliPoint and SetPoint), the middle (wheel) button, the 4th button, and the 5th button might not be set, even when they are pressed.
  • On Linux (GTK), the 4th button and the 5th button are not supported. In addition, a mouseup event always has the releasing button information in this attribute value.
  • On Mac OS X 10.5, the buttons attribute always returns 0 because there is no platform API for implementing this feature.

[2] This feature got implemented in bug 276941.

See also

文档标签和贡献者

 此页面的贡献者: isun, liuzihao, crazybear
 最后编辑者: isun,