版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。
禁用某键,在标签上添加onkeydown事件,onkeydown事件书写如下:
js禁用tab键:
onkeydown="if(event.keyCode==9){event.keyCode=0;event.returnValue=false;}"
js禁用Enter键:
onkeydown="if(event.keyCode==13){event.keyCode=0;event.returnValue=false;}
注意:
想要禁用某控制键,前提是知道这个控制键的键码值(keyCode)
js键盘的键码值整理如下:
keycode8= BackSpace BackSpace keycode9= Tab Tab keycode12= Clear keycode13= Enter keycode16= Shift_L keycode17= Control_L keycode18= Alt_L keycode19= Pause keycode20= Caps_Lock keycode27= Escape Escape keycode32= space space keycode33= Prior keycode34= Next keycode35= End keycode36= Home keycode37= Left keycode38= Up keycode39= Right keycode40= Down keycode41= Select keycode42= Print keycode43= Execute keycode45= Insert keycode46= Delete keycode47= Help keycode48=0 equal braceright keycode49=1 exclam onesuperior keycode50=2 quotedbl twosuperior keycode51=3 section threesuperior keycode52=4 dollar keycode53=5 percent keycode54=6 ampersand keycode55=7