如何创建在 jQuery 中调用事件的快捷键(就像我按Alt + A
然后调用按钮单击函数。但不是如果Alt + V + A
).
我不知道这是否是最好的解决方案,但也许有帮助:
警告:这不是经过实战考验的解决方案
var pressedKeys = [];
document.addEventListener('keydown', function(e) {
if(e.altKey){
var idx = pressedKeys.indexOf(e.which);
if(idx < 0) pressedKeys.push(e.which);
}
});
document.addEventListener('keyup', function(e) {
// 65 means A
if (e.altKey && e.which == 65){
if(pressedKeys.length === 2)
console.log("Alt + A shortcut combination was pressed");
}
var idx = pressedKeys.indexOf(e.which);
if(idx > -1) pressedKeys.splice(idx, 1);
});
您可以看到上面的代码正在运行,here https://codepen.io/digitalify/pen/eLBMZa在代码笔上
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)