window.event.keyCode与event.which

      Netscape/Firefox/Opera中不支持 window.event.keyCode,需要用event.which代替
因为IE用event.keCode方法获取当前被按下的键盘按键值,而NetScape/FireFox/Opera用的则是event.which


文本框中填入onkeydown属性
onkeydown="javascript:if((window.event?window.event.keyCode:event.which)==13 && longinTest()) form1.submit();"

<script language="javascript">
function longinTest() {
	var name = document.form1.userName.value;
	var pass= document.form1.passWord.value;
	if (name == "" || pass== "") {
		if (name == "" && pass== "") {
			alert("请输入用户名和密码!");
			document.form1.userName.focus();
		} else if (name == "" && pass!= "") {
			alert("请输入用户名!");
			document.form1.userName.focus();
		} else if (name != "" && pass== "") {
			alert("请输入密码!");
			document.form1.passWord.focus();
		}
		return false;
	} else {
		return true;
	}
}
</script>

你可能感兴趣的:(keycode)