<form name="form1" method="post" action="register.jsp" onSubmit="return check()">中返回
check()函数,check()在脚本定义:
<script>
function check(){
username=document.form1.username.value;
pwd1=document.form1.pwd1.value;
pwd2=document.form1.pwd2.value;
year=document.form1.year.value;
month=document.form1.month.vlaue;
day=document.form1.day.value;
email=document.form1.email.value;
interest=document.form1.interest.value;
if(username.length<6||username.length>15){
alert("用户名长度必须在6-15位之间!");
return false;
}
if(pwd1.length<6||pwd1.length>20){
alert("密码长度必须在6-20位之间!");
return false;
}
if(pwd1!=pwd2){
alert("两次输入的密码不匹配!");
return false;
}
if(year.length!=4||month>13||month<1||day>32||day<1){
alert("生日输入不正确!");
return false;
}
if(email=""||(email.indexOf('@')==-1||(email.indexOf('.')==-1)){
alert("电子邮件格式不正确!");
return false;
}
return true;
}
</script>
为什么每次输入不正确的信息,比如:两次输入的密码不同,不弹出alert()的内容呢?请大家帮帮忙吧!!!
check()函数,check()在脚本定义:
<script>
function check(){
username=document.form1.username.value;
pwd1=document.form1.pwd1.value;
pwd2=document.form1.pwd2.value;
year=document.form1.year.value;
month=document.form1.month.vlaue;
day=document.form1.day.value;
email=document.form1.email.value;
interest=document.form1.interest.value;
if(username.length<6||username.length>15){
alert("用户名长度必须在6-15位之间!");
return false;
}
if(pwd1.length<6||pwd1.length>20){
alert("密码长度必须在6-20位之间!");
return false;
}
if(pwd1!=pwd2){
alert("两次输入的密码不匹配!");
return false;
}
if(year.length!=4||month>13||month<1||day>32||day<1){
alert("生日输入不正确!");
return false;
}
if(email=""||(email.indexOf('@')==-1||(email.indexOf('.')==-1)){
alert("电子邮件格式不正确!");
return false;
}
return true;
}
</script>
为什么每次输入不正确的信息,比如:两次输入的密码不同,不弹出alert()的内容呢?请大家帮帮忙吧!!!
if(document.form1.username.value.length<6||document.form1.username.value.length>15){
alert("用户名长度必须在6-15位之间!");
return false;
}
比如:month=document.form1.month.vlaue;中value写错了还有if(email=""||(email.indexOf('@')==-1||(email.indexOf('.')==-1))这句话,括号不匹配
document.all.form1.pwd1.value