当前位置: 代码迷 >> JavaScript >> onsubmit不见效
  详细解决方案

onsubmit不见效

热度:209   发布时间:2012-10-14 14:55:07.0
onsubmit不生效
写了个验证用户名密码的JavaScript,但这个函数死活不生效,大家帮忙看看怎么回事?
即使改成onsubmit=false,一个是跳转下一个页面。


<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "
http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="CSS/default.css" />
<title>欢迎注册</title>
<script type="text/javascript">
function validate1()
{
return false;
var username = document.getElementById("username");
var password = document.getElementById("password");
var repassword = document.getElementById("repassword");

if (username.value == "")
{
alert("用户名不能为空!");
return false;
}

if (password.value != repassword.value)
{
alert("两次输入的密码不一致,请重新输入!");
return false;
}

if (password.value.length > 10 || password.value.length < 6)
{
alert("密码长度应不少于6位,不多于10位! ");
retrun false;
}
return false;
}
</script>
</head>

<body>

<div class="boldcenter">
<form onsubmit="return validate1();" action="/PrivateSystem/regist2.jsp">
<br> <br> <br> <br>欢迎注册,请认真填写以下内容:<br> <br><br> 
新用户名:<input type="text" name="username" id="username" /><br>
输入密码:<input type="password" name="password" id="password" /><br>
重复密码:<input type="password" name="repassword" id="repassword" /><br>
<input type="submit" value="下一步"/>&nbsp;&nbsp;&nbsp;<input
type="reset" value="重置" /><br>
</form>
</div>

</body>
</html>

------解决方案--------------------
if (password.value.length > 10 || password.value.length < 6)
{
alert("密码长度应不少于6位,不多于10位! ");
return false; //return 写错了
}