Which mouse button was pressed?
let text = "You pressed button: " + event.button;
Try it Yourself »
The button
property returns which mouse button is pressed when a mouse event occurs.
The button
property is mostly used with the onmousedown
event.
The button
property is read-only.
event.button
Return Value: | A Number. Which mouse button that was pressed: 0 : Left button 1 : Wheel or middle button (if present) 2 : Right button For a left-hand configured mouse, the values are reversed. |
---|---|
DOM Version: | DOM Level 2 Events |
event.button
is a DOM Level 2 (2001) feature.
It is fully supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | 9-11 |
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!