登陆框默认按回车不能自动跳转至下一控件,只能跳转至CLICK事件,输入很不舒服,所以做了如下改动:
HTML
用户名:<input type="text" id="UserAccount" onKeyPress="JumpByEnter(UserPwd)" />
密码:<input name="UserPwd" type="password" onKeyPress="JumpByEnter(Submit)">
JavaScript:
JumpByEnter(UserPwd) 函数功能:输入完用户名按回车,焦点转向密码输入框
IsEnterKeyPress()功能:输入完密码并按回车,则登录
function JumpByEnter(NextElement){
var lKeyCode = (navigator.appname=="Netscape")?event.which:window.event.keyCode; //event.keyCode按的建的代码,13表示回车 if ( lKeyCode == 13 ){NextElement.focus();
}irfirefox2.0中不支持 window.event.keyCode,
但是我们可以用event.which代替。但是为了使其能更具有普遍的兼容性,最好用event.keyCode|| event.which.
用法举例:C#后台代码:txtHampooPN.Attributes.Add("onkeydown", "if(event.keyCode == 13 && " + txtHampooPN.ClientID + ".value.length ==0)return false; ");
txtPinyinCode.Attributes.Add("onkeydown", "if(event.which||event.keyCode){if ((event.which==13 ) || (event.keyCode==13)) { document.getElementById('" + btnLocation.UniqueID + "').click();return false;}}else{return true};");
键码值参考: