Gre*_*ims 6 javascript mouselistener
简而言之,有什么方法可以检测JavaScript中的其他鼠标按钮按下情况吗?其余的鼠标输入未对此进行记录,因此我想它不在标准实现中。
是否有其他方法(例如库)可以启用额外的鼠标按钮?
是的,您可以这样做,请检查MouseEvent.button,请参见下面的示例,该示例将检测 3 和 4 个按钮的点击。
一些定点设备提供或模拟更多按钮。要表示此类按钮,必须将每个连续按钮的值加倍(在二进制系列 8、16、32 中,...),如https://www.w3.org/TR/DOM-Level-3- 中所述事件/#events-mouseevents
var whichButton = function (e) {
// Handle different event models
var e = e || window.event;
var btnCode;
if ('object' === typeof e) {
btnCode = e.button;
switch (btnCode) {
case 3:
console.log('Browser Back button clicked.');
break;
case 4:
console.log('Browser Forward button clicked.');
break;
default:
console.log('Unexpected code: ' + btnCode);
}
}
}Run Code Online (Sandbox Code Playgroud)
<button onmouseup="whichButton(event);" oncontextmenu="event.preventDefault();">Click with mouse...</button>Run Code Online (Sandbox Code Playgroud)
小智 -1
var whichButton = function (e) {
// Handle different event models
var e = e || window.event;
var btnCode;
if ('object' === typeof e) {
btnCode = e.button;
switch (btnCode) {
case 3:
console.log();
break;
case 4:
console.log();
break;
default:
console.log('Unexpected code: ' + btnCode);
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1179 次 |
| 最近记录: |