<html>
<head>
<script language="javascript">
function checkForm(){
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;
var dpassword = document.getElementById("dpassword").value;
if(username.length<6 || username.length>12){
alert("提示:\n\n用户名称必须大于6位,小于12位!");
document.getElementById("username").value = "";
document.getElementById("username").focus();
return false;
}
if(password.length<6 || password.length>12){
alert("提示:\n\n密码必须大于6位,小于12位!");
document.getElementById("password").value = "";
document.getElementById("password").focus();
return false;
}
if(dpassword.length<6 || dpassword.length>12){
alert("提示:\n\n密码必须大于6位,小于12位!");
document.getElementById("dpassword").value = "";
document.getElementById("dpassword").focus();
return false;
}
if(password != dpassword){
alert("提示:\n\n两次输入的密码不同!");
return false;
}
}
</script>
</head>
<body>
<form action="RegisterServlet" method="post">
<div class="fielddiv">
<label>
用户名:
</label>
<input type="text" name="username"/>
</div>
<div class="fielddiv">
<label>
密 码:
</label>
<input type="password" name="password" />
</div>
<div class="fielddiv">
<label>
重复密码:
</label>
<input type="password" name="dpassword"/>
</div>
<div class="center">
<input type="submit" class="buttom" value="注册" onclick="return checkForm()"/>
<input type="reset" class="buttom" value="清空"/>
</div>
</form>
</body>
</html>
为什么onclick中要加上return才能判断成功 才不会继续运行下去 为什么直接写onclick="checkForm()" 注册的错误格式还会继续提交给服务器