js: js判断回车键
表单提交的时候大多数用户都习惯用回车键来进行提交,页面接受回车键的处理如下:
if(navigator.userAgent.indexOf("MSIE")>0) { //IE document.onkeydown=function(){
if(13 == event.keyCode){
alert('browser is ie and enter key down');
}
} }else{ //非IE window.onkeydown=function(){
if(13 == event.keyCode){
alert('browser is not ie and enter key down');
}
}
}
附常用功能键
常数 值 描述
vbKeyBack 8 BACKSPACE 键
vbKeyTab 9 TAB 键
vbKeyReturn 13 ENTER 键
vbKeyShift 16 SHIFT 键
vbKeyControl 17 CTRL 键
vbKeyCapital 20 CAPS LOCK 键
vbKeyEscape 27 ESC 键
vbKeySpace 32 SPACEBAR 键
vbKeyPageUp 33 PAGEUP 键
vbKeyPageDown 34 PAGEDOWN 键
vbKeyEnd 35 END 键
vbKeyPrint 42 PRINT SCREEN 键
vbKeyDelete 46 DEL 键
vbKeyNumlock 144 NUM LOCK 键