MouseEvent.buttons - Web API 接口参考 编辑
只读属性
MouseEvent.buttons
指示事件触发时哪些鼠标按键被按下。
每一个按键都用一个给定的数(见下文)表示。如果同时多个按键被按下,buttons 的值为各键对应值做与计算(+)后的值。例如,如果右键(2)和滚轮键(4)被同时按下,buttons 的值为 2 + 4 = 6。
注意:属性 MouseEvent.button 和 MouseEvent.buttons 是不同的。MouseEvent.buttons 可指示任意鼠标事件中鼠标的按键情况,而 MouseEvent.button 只能保证在由按下和释放一个或多个按键时触发的事件中获得正确的值。
语法
var buttonPressed = instanceOfMouseEvent.buttons
返回值
一个数字,用来标识鼠标按下的一个或者多个按键。如果按下的键为多个,则值等于所有按键对应数值进行或(|)运算的结果。
0
: 没有按键或者是没有初始化1
: 鼠标左键2
: 鼠标右键4
: 鼠标滚轮或者是中键8
: 第四按键 (通常是“浏览器后退”按键)16
: 第五按键 (通常是“浏览器前进”)
Specifications
Specification | Status | Comment |
---|---|---|
Document Object Model (DOM) Level 3 Events Specification MouseEvent.buttons | Obsolete | Initial definition |
Browser compatibility
We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论