Javascipt: 阻擋按鍵

window.addEventListener('keydown', stopKeys);
window.addEventListener('keyup', stopKeys);
function stopKeys(e){
let thekeys = [33,34,35,36]; // 填入需阻擋keycode
if(thekeys.indexOf(e.keyCode)>-1){
e.preventDefault();
}
}

留言