程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> select-為什麼onsubmit在審核地址的時候就失效了呢?

select-為什麼onsubmit在審核地址的時候就失效了呢?

編輯:編程綜合問答
為什麼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;

}

最佳回答:


你的checkUaddr函數沒有啊。發代碼的時候用</>格式化一下就好了

w100224
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved