Java项目中,如何实现按回车键实现登录!

方法一:

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
  <title>Check Score</title>
<script language="JavaScript">
function keyLogin(){
   if (event.keyCode==13){  //回车键的键值为13
   		alert("回车!");
   		document.getElementById("login").click(); //调用登录按钮的登录事件
	}
}
</script>
</head>
<body onkeydown="keyLogin();">
	<input id="login" value="登录" type="button" onClick="alert('调用成功!')">
</body>
</html>

方法二:

<span style="font-size:18px;"><html xmlns="http://www.w3.org/1999/xhtml" >
<head>
  <title>Check Score</title>
<script language="JavaScript">
function KeyDown()
{
  if (event.keyCode == 13)
  {
	alert("回车!");
    event.returnValue=false;
    event.cancel = true;
    Form1.btnsubmit.click();
  }
}
</script>
</head>
<body>
<form name="Form1" method="">
	用户名:<INPUT TYPE=text SIZE=20 maxlength =8 onkeydown="KeyDown();">
	密码:<INPUT TYPE=password SIZE=20 maxlength =8 onkeydown="KeyDown();">
	<input type="submit" name="btnsubmit" value="提交" />
</form>
</body>
</html></span>
注:js对方法名的大小写很敏感!

你可能感兴趣的:(按回车键实现登录)