没有form表单情况下敲回车键提交表单的js代码

  作者:bea

<html> <head> <title></title> <script type="text/javascript"> function enterPress(e) { if (e.keyCode == 13) { login(); } } function login(){ //登录验证等 alert('login'); } </script> </head> <body>


<html>
<head>
<title></title>
<script type="text/javascript">
function enterPress(e) {
if (e.keyCode == 13) {
login();
}
}
function login(){
//登录验证等
alert('login');
}
</script>
</head>
<body>
<table id='logintable' border="1" cellpadding="0" cellspacing="0">
<tr>
<td>
Username:<input id="userName" type="text" name="userName"
style="width: 90px;" onkeydown="javascript: enterPress(event);"/>
</td>
<td>
Password:<input id="password" type="password" name="password"
style="width: 90px;" onkeydown="javascript: enterPress(event);"/>
</td>
<td>
<input id="login" type="button" value="Login" onclick="login()" />
</td>
</tr>
</table>
</body>
</html>




[Ctrl+A 全选 注:
如需引入外部Js需刷新才能执行]



有用  |  无用

猜你喜欢