我正在尝试建立一个使用数字键盘作为键盘快捷键来按下不同按钮的网站。对于其中一个事件,我需要超过 9 个快捷方式。为了在用户端保持简单,我想使用数字锁定键 #144。问题是,当他们使用数字锁定键时,它会阻止数字在将来按下按钮时起作用。我试过使用 preventDefault(); 功能,但它似乎不起作用。有没有其他方法可以让我做到这一点?
if (e.which == 144) { // numlock on the numberpad
preventDefault();
document.getElementById("button1").click();
}
if (e.which == 96) { // 0 on the numberpad
document.getElementById("button2").click();
}