<?xml version="1.0" encoding="UTF-8" ?>
<html>
<head>
<title>验证账号密码:</title>
<script type="text/javascript">
function checkInfo() {
var u = document.getElementById("user");
var p = document.getElementById("pswd");
if (u.value == "") {
alert("Please enter your account!");
u.focus();
return false;
}
if (p.value == "") {
alert("Password can not be empty!");
p.focus();
return false;
}
return true;
}
//这种方法绑定事件无效
//如果使用window.onload=function(){}这种方法则会出现错误
//所以直接在标签的属性中绑定
//document.getElementById("login").onsubmit = checkInfo;
</script>
</head>
<body>
<h1>请输入账号密码:</h1>
<!--使用在checkInfo()函数前面加上return则,如果checkInfo返回true才提交,否则不会提交-->
<form id="login" onsubmit="return checkInfo()" method="post"
action="/ServletDemo/servlet/LoginServlet">
账号: <input name="user" id="user" type="text" /><br /> 密码:<input name="pswd" id="pswd"
type="password" /><br /> <input type="reset" value="重置" /> <input
type="submit" value="提交" />
</form>
</body>
</html>