w100224 2015-01-01 11:55 采纳率: 85.7%
浏览 1755
已采纳

为什么onsubmit在审核地址的时候就失效了呢?

其他的账号密码都可以拦住,但是地址不管有没有选,只要提交就可以跳到servlet,而且只要账号密码都填了,就算onsubmit里面check函数全部设置为return false 一样可以跳

<head>
    <base href="<%=basePath%>">

    <title>用户注册</title>

    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
<script language="javascript" src="checkForm.js"></script>
<script language="javascript" type="text/javascript"  src="<%=basePath%>/js/My97DatePicker/WdatePicker.js"></script>
<!--  二级联动下拉框  -->
<script language="JavaScript" type="text/javascript">
        var city=[    
            ["北京","天津","上海","重庆"],  
            ["南京市","苏州市","南通市","常州市"],  
            ["福州市","福安市","龙岩市","南平市"],  
            ["广州市","潮阳市","潮州市","澄海市"],  
            ["兰州市","白银市","定西市","敦煌市"]  
        ];    
        function getCity(){    
            var sltProvince=document.userform.province;  
            var sltCity=document.userform.city;    
            var provinceCity=city[sltProvince.selectedIndex - 1];    
            sltCity.length=1;    
            for(var i=0;i< provinceCity.length;i++){    
                sltCity[i+1]=new Option(provinceCity[i],provinceCity[i]);    
                }    
        }    
</script>    

  </head>

  <body>
    <form  name="userform" action="servlet/AddUserServlet" method="post" onsubmit="return check()">
   <table align="center" border="1" width="440px">
   <tr>
   <td colspan="2" align="center" >用户注册表</td>
   </tr>
      <tr>
      <td align="center">用户姓名</td>
      <td>
      <input type="text" name="uname" size="" onblur="checkUname(this.value)">
      <span id="unameErr"></span>
      </td>
      </tr>
      <tr>
      <td align="center">用户密码</td>
      <td>
      <input type="password" name="upwd" onblur="checkUpwd(this.value)">
      <span id="upwdErr"></span>
      </td>
      </tr>
      <tr>
      <td align="center">确认密码</td>
      <td>
      <input type="password" name="upwd2" onblur="checkUpwd2(this.value)">
      <span id="upwd2Err"></span>
      </td>
      </tr>
      <tr>
      <td align="center">用户性别</td>
      <td>
      <input type="radio" name="usex" value="男" checked>男
      <input type="radio" name="usex" value="女">女
      </td>
      </tr>

      <tr>
      <td align="center">出生日期</td>
      <td>
      <input name="strbirth" class="Wdate" type="text" id="d16" onfocus="WdatePicker({position:{right:100,top:50}})"/>
      </td>
      </tr>
       <tr>
      <td align="center">用户住址</td>
      <td>
             <SELECT NAME="province" onChange="getCity()" onblur="checkUaddr(this.value)">  
                <OPTION VALUE="">请选择所在省份</OPTION>  
                <OPTION VALUE="直辖市">直辖市</OPTION>  
                <OPTION VALUE="江苏省">江苏省</OPTION>  
                <OPTION VALUE="福建省">福建省</OPTION>  
                <OPTION VALUE="广东省">广东省</OPTION>    
                <OPTION VALUE="甘肃省">甘肃省</OPTION>  
            </SELECT>    
            <SELECT NAME="city" onblur="checkUaddr(this.value)">    
                <OPTION VALUE="">请选择所在城市</OPTION>    
            </SELECT>    
      <span id="uaddrErr"></span>
      </td>
      </tr>
      <tr><td colspan="2" align="center">
      <input type="submit" value="确定" style="width: 82px; ">
      <input type="reset" value="重置" style="width: 82px; ">
      </td></tr>
   </table>

这是checkForm.js


function check() {
if(!checkUname(document.userform.uname.value)){
    return false;
}else if(!checkUpwd(document.userform.upwd.value)){
    return false;
}else    if(!checkUpwd2(document.userform.upwd2.value)){
    return false;
}else    if(!checkUaddr(document.userform.province.value)){
    return false;
}else    if(!checkUaddr(document.userform.city.value)){
    return false;
}else   {
return true;
}

}

function checkUname(str) {
if(str == "") {
document.getElementById("unameErr").innerHTML="用户名不能为空";
userform.uname.focus();
return false;
}else {
document.getElementById("unameErr").innerHTML="验证通过";
return true;
}
}
function checkUpwd(str) {
if(str == "") {
document.getElementById("upwdErr").innerHTML="密码不能为空";
userform.upwd.focus();
return false;
}else if(strlen(str) < 6) {
document.getElementById("upwdErr").innerHTML="密码不能低于6位";
userform.upwd.focus();
return false;
}
else {
document.getElementById("upwdErr").innerHTML="验证通过";
return true;
}
}
function checkUpwd2(str) {
if(str == "") {
document.getElementById("upwd2Err").innerHTML="密码不能为空";

userform.upwd.focus();
return false;
}else if(str != document.userform.upwd.value) {
document.getElementById("upwd2Err").innerHTML="两次输入的密码不一致";

userform.upwd2.focus();
return false;
}else {
document.getElementById("upwd2Err").innerHTML="验证通过";
return true;
}
}

function checkUaddr(str) {
if(str == "") {
document.getElementById("uaddrErr").innerHTML="地址不能为空";

userform.uaddr.focus();
return false;
}else {
document.getElementById("uaddrErr").innerHTML="验证通过";
return true;
}
}

function strlen(str) {
var i;
var len=0;
for(i = 0;i < str.length;i++) {
if(str.charCodeAt(i) > 255) len += 2;
else len++;
}
return len;

}

  • 写回答

2条回答 默认 最新

  • 斯洛文尼亚旅游 2015-01-01 12:55
    关注

    你的checkUaddr函数没有啊。发代码的时候用</>格式化一下就好了

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题