MDN’s new design is in Beta! A sneak peek: https://blog.mozilla.org/opendesign/mdns-new-design-beta/

MouseEvent.buttons

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

The MouseEvent.buttons read-only property indicates which buttons are pressed on the mouse when the event is triggered.

Each button that can be pressed is represented by a given number (see below). If more than one button is pressed, the value of the buttons is combined to produce a new number. For example, if the right button (2) and the wheel button (4) are pressed, the value is equal to 2|4, which is 6.

Note: Do not confuse this property with the MouseEvent.button property. The MouseEvent.buttons property indicates the state of buttons pressed during any kind of mouse event, while the MouseEvent.button property only guarantees the correct value for mouse events caused by pressing or releasing one or multiple buttons.

Syntax

var buttonPressed = instanceOfMouseEvent.buttons

Return value

标示鼠标按下了一个或者多个按键,如果按下的键为多个,值则为多个

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

Specifications

Specification Status Comment
Document Object Model (DOM) Level 3 Events Specification
MouseEvent.buttons
Working Draft 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

文档标签和贡献者

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