当我按下数字键盘 1 时,我希望我的代码到 console.log
我试过了,但没有用:
function presskey1(e){
if(e.keyCode == 97){
console.log(Element)
}
}
presskey1();
97 = 小键盘 1 代码键
最佳答案
这是您可以做到的!您应该为 keydown 事件使用事件监听器,并且数字键盘 1 的键码是 Numpad1
document.addEventListener('keydown', keyPressed);
function keyPressed(e) {
if(e.code == "Numpad1") {
console.log("Numpad1 Pressed");
}
}
关于javascript - 当我按下键盘上的某个键时如何控制台日志?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64233113/