我想禁用 F1 键。我尝试这样做,但它在 Chrome 中不起作用。
document.onhelp=function() {return false;};
window.onhelp=function() {return false;};
最佳答案
使用preventDefault
:
window.addEventListener("keydown",function (e) {
if (e.keyCode === 112) {
e.preventDefault();
}
})
这很简短,但是,为了拥有与浏览器更兼容的东西,check this .
关于javascript - 如何禁用F1键?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38673629/