javascript java 數據庫 網絡 session app dom ide this 編碼 欄目 Ajax 简体版
原文   原文鏈接
如下是要用到的js代碼,通常單獨放一個js文件,本例放置到myjs.js文件當中,如下是引用該文件的代碼;   
<script language="javascript" src="myjs.js" type="text/javascript"></script>
代碼以下:
 
       
var icon = '<img src= "p_w_picpath/warning.gif" width= "14" height= "14" border= "0" align= "top">';
         var ns = [ "Loginname", "Password", "Passw", "Mail", "Companyname", "Tel", "Fax", "Dizhi", "Zip", "Linkname", "Shouji", "Url", "Jieshao", "Yanzheng"];
        
         // 換一張圖片
         function SetImage(){
           //  
           var rod =  Math.round(Math.random() * 100);
          $('ImaYanZhen').src = "p_w_picpath/loading.gif"; //  
          $('ImaYanZhen').src = "ValidateCode.aspx?id=" + rod;
        }
        
         function checkUsr(s){  
             var ma = [ "用戶名(4-16位)!", "用戶名由數字、英文、下劃線、中槓線組成!"];
             if(!limitLen(s,4,16)){
             showInfo( "Loginname",ma[0]);
             return false;
            }
             if(!hasAccountChar(s)){
             showInfo( "Loginname",ma[1]);
             return false;
            }
            showInfo( "Loginname");
             return true;
        }
        
         function isLoginname(s)
        {
             var ma = [ "用戶名(4-16位)!", "用戶名由數字、英文、下劃線、中槓線組成!", "此用戶名已被註冊,請另換一個。", "請等待,數據加載中..."];
             var icons = '<img src= "p_w_picpath/loading.gif" width= "14" height= "14" border= "0" align= "top">';
            
             if(!limitLen(s,4,16)){
             showInfo( "Loginname",ma[0]);
             return false;
            }
             if(!hasAccountChar(s)){
             showInfo( "Loginname",ma[1]);
             return false;
            }
            
            $( "TisiLoginname").className = "focus";
            $( "LoginnameInfo").innerHTML = icons + ma[3];
              
           var bRet = join.GetReturnCode(s).value;
           if(bRet == "1"){
                $( "TisiLoginname").className = "error";
                $( "LoginnameInfo").innerHTML = icon + ma[2];
           }
           else
           {
                showInfo( "Loginname");
           }
        }
        
       function checkPwd(s){
   var ma = [ "密碼(6-20位)!", "密碼不能包含中文或全角符號!", "兩次輸入的密碼不一致!"];
   if(!limitLen(s,6,16)){
   showInfo( "Password",ma[0]);
   return false;
  }
   if(hasChineseChar(s)){
   showInfo( "Password",ma[1]);
   return false;
  }
  showInfo( "Password");
   return true;
}
  
function checkPwd2(s){
     var ma = [ "密碼(6-20位)!", "密碼不能包含中文或全角符號!", "兩次輸入的密碼不一致!"];
     if(!limitLen(s,6,16)){
   showInfo( "Passw",ma[0]);
   return false;
  }
   if(hasChineseChar(s)){
   showInfo( "Passw",ma[1]);
   return false;
  }
        
         if( s==trim($( "TexPassword").value))
        {
            showInfo( "Passw");
             return true;
        }
     else{
         showInfo( "Passw",ma[2]);
       return false;
     }
}
  
function checkEml(s){
   var ma = [ "請輸入經常使用郵件!", "郵件格式不正確!"];
   if(s.length < 5){
   showInfo( "Mail",ma[0]);
   return false;
  }
   if(!isEmail(s)){
   showInfo( "Mail",ma[1]);
   return false;
  }
  showInfo( "Mail");
   return true;
}
  
   function checkCompany(s){  
   var ma = [ "企業名稱不能爲空!"];
   if(!limitLen(s,1,100)){
   showInfo( "Companyname",ma[0]);
   return false;
  }
  showInfo( "Companyname");
   return true;
}  
  
   function checkPhone(){  
       var ma = [ "電話國家代碼不能爲空!", "電話區號不能爲空!", "電話號碼不正確!"];
       var gj = $( "TexTelGJ").value;
       var qh = $( "TexTelQH").value;
       var s = $( "TexTel").value;
       if(gj.length == 0){
       showInfo( "Tel",ma[0]);
       return false;
      }
       if(qh.length == 0){
       showInfo( "Tel",ma[1]);
       return false;
      }  
       if(!isPhone(gj + "-" + qh+ "-" + s)){
       showInfo( "Tel",ma[2]);
       return false;
      }  
      showInfo( "Tel");
       return true;
     }  
        
         function checkFax(){
             var ma = [ "傳真國家代碼不能爲空!", "傳真區號不能爲空!", "傳真號碼不正確!"];
       var gj = $( "TexFaxGJ").value;
       var qh = $( "TexFaxQH").value;
       var s = $( "TexFax").value;
        
       if(gj.length == 0 && qh.length == 0 && s.length == 0)
      {
          $( "TisiFax").className = "lond";
          $( "FaxInfo").innerHTML = "";
           return true;
      }
       if(gj.length == 0){
       showInfo( "Fax",ma[0]);
       return false;
      }
       if(qh.length == 0){
       showInfo( "Fax",ma[1]);
       return false;
      }  
       if(!isPhone(gj + "-" + qh + "-" + s)){
       showInfo( "Fax",ma[2]);
       return false;
      }  
      showInfo( "Fax");
       return true;
        }
        
        
         function checkDizi(s){  
             var ma = [ "企業地址不能爲空!"];
             if(!limitLen(s,1,100)){
             showInfo( "Dizhi",ma[0]);
             return false;
            }
            showInfo( "Dizhi");
             return true;
        }
        
     function checkZip(s){
             var ma = [ "郵政編碼格式不正確!"];
             if(s.length == 0){
                $( "TisiZip").className = "lond";
          $( "ZipInfo").innerHTML = "中國地區用戶請填寫規範的6位郵政編碼。";
           return true;
            }
             if(!isZip(s)){
             showInfo( "Zip",ma[0]);
             return false;
            }
            showInfo( "Zip");
             return true;
     }
      
     function checkShengfen(){
             var ma = [ "請選擇公司所在省份!", "請選擇公司所在市區!"];
             var sh,qu;
            sh = $( "DropShengfen").selectedIndex;
            qu = $( "DropDiqu").selectedValue;
             if(sh == 0){
                showInfo( "Shengfen",ma[0]);
                 return false;
            }
             if(qu == ""){
                showInfo( "Shengfen",ma[1]);
                 return false;
            }
            showInfo( "Shengfen");
             return true;
     }
      
     function checkLinkname(s){
         var ma = [ "聯繫人不能爲空!"];
       if(!limitLen(s,2,20)){
       showInfo( "Linkname",ma[0]);
       return false;
      }
      showInfo( "Linkname");
       return true;
    }
    
     function checkShouji(s){
         var ma = [ "手機格式不正確!"];
         if(s.length == 0){
             $( "TisiShouji").className = "lond";
          $( "ShoujiInfo").innerHTML = "建議您填寫,以便潛在客戶及時與您取得聯繫!";
           return true;
         }
         if(!isMobile(s)){
             showInfo( "Shouji",ma[0]);
             return false;
         }
      showInfo( "Shouji");
       return true;
    }
    
     function checkUrl(s){
         var ma = [ "網址格式不正確!"];
         if(s == "HTTP://" || s.length == 0){
             $("TisiUrl").className = "lond";
          $("UrlInfo").innerHTML = "請在網址前加:HTTP://。";
          return true;
         }
         if(!isURL(s)){
             showInfo("Url",ma[0]);
             return false;
         }
      showInfo("Url");
      return true;
    }
    
    function checkJieshao(s){
         var ma = ["企業介紹不能爲空!"];
      if(!limitLen(s,1,2000)){
       showInfo("Jieshao",ma[0]);
       return false;
      }
      showInfo("Jieshao");
      return true;
    }
    
    
    function checkYanzheng(s){
         var ma = ["驗證碼不能爲空!","驗證碼爲4位字母或數字!","驗證碼輸入錯誤,請從新輸入!"];
         if(s.length == 0)
         {
             showInfo("Yanzheng",ma[0]);
             return false;
         }
         if(s.length < 4)
         {
             showInfo("Yanzheng",ma[1]);
             return false;
         }else{
            var ses = join.sessions().value;
            if(s.toLowerCase() != ses)
            {
                 showInfo("Yanzheng",ma[2]);
                 return false;
            }
        }
        showInfo("Yanzheng");
     return true;
    }
    
        function inputfocus(n,i)
        {
            var ma = ["4-16位;只限數字(0-9)和英文(a-z),不區分大小寫;建議使用公司名稱簡稱。",
                "6-20位,區分大小寫, 不能與用戶名相同;建議爲英文字母(a-z)和數字(0-9)結合,便於記憶,不易被猜出。",
                "請再輸入一遍上面填寫的密碼。",
                "請填寫經常使用的電子郵箱,這是客戶聯繫您的一種方式!",
                "請使用中文填寫貴公司的全稱。",
                "很重要!這是客戶聯繫您的主要方式!",
                "請填寫完整的公司地址。",
                "中國地區用戶請填寫規範的6位郵政編碼。",
                "請選擇公司所在省市。",
                "請填寫聯繫人的真實姓名。",
                "建議您填寫,以便潛在客戶及時與您取得聯繫!",
                "請在網址前加:HTTP://。",
                "能夠填入最多2000字的企業介紹。",
                "請輸入左側顯示的驗證字符串(不區分大小寫)。"];
            var fdo = $("Tisi" + n);
            var ido = $(n + "Info");
            fdo.className = "focus";
            ido.innerHTML = ma[i];
        }
        
        function showInfo(n,s){
            var fdo = $("Tisi" + n);
            var ido = $(n + "Info");
            if(typeof s == 'undefined'){
                fdo.className = "ok";
                ido.innerHTML = "填寫正確!";
            }else{
                fdo.className = "error";
                ido.innerHTML = icon + s;
            }
        }
        
        function submits(){
            checkUsr($("Tex" + ns[0]).value);
            checkPwd($("Tex" + ns[1]).value);
            checkPwd2($("Tex" + ns[2]).value);
            checkEml($("Tex" + ns[3]).value);
            checkCompany($("Tex" + ns[4]).value);
            checkPhone();
            checkFax();
            checkDizi($("Tex" + ns[7]).value);
            checkZip($("Tex" + ns[8]).value);
            checkShengfen();
            checkLinkname($("Tex" + ns[9]).value);
            checkShouji($("Tex" + ns[10]).value);
            checkUrl($("Tex" + ns[11]).value);
            checkJieshao($("Tex" + ns[12]).value);
            checkYanzheng($("Tex" + ns[13]).value);
            
            for(var i=0;i<ns.length;i++){
               if( $("Tisi" + ns[i]).className == "error"){
                    $("Tex" + ns[i]).focus();  
                   return false;
               }
               else{
                    continue;
               }
            }
           // return true;
        var  fax = "", fw = "", mes = "因爲網絡緣由註冊失敗,請聯繫管理人員。";
        var baomi = 0;
        var tel =  $("TexTelGJ").value + "-" + $("TexTelQH").value +"-"+$("TexTel").value;
        
        if(trim($("TexFax").value) != ""){
            fax =  $("TexFaxGJ").value + "-" + $("TexFaxQH").value +"-"+$("TexFax").value;
        }
        
        for(var i =1;i<7;i++){
            if($("CheckBox" + i).Checked == "Checked"){
                fw += $("CheckBox" + i).value + ",";
                }
        }
        
        if($("RadioButtonList1_0").checked == "checked"){
            baomi = 0;
            }
            else{
            baomi = 1;
            }
            
        var a1 = $("TexLoginname").value;
        var a2 = $("TexPassword").value;
        var a3 = $("TexMail").value;
        var a4 = $("TexCompanyname").value;
        var a5 = $("TexDizhi").value;
        var a6 = $("TexZip").value;
        var a7 = $("DropShengfen").value;
        var a8 = $("DropDiqu").value;
        var a9 = $("TexLinkname").value;
        var a10 = $("TexShouji").value;
        var a11 = $("TexUrl").value;
        var a12 = $("DropDownList3").value;
        var a13 = $("TexJieshao").value;
          
        var bRet = join.AddCompanya(a1,a2,a3,a4,tel, fax,a5,a6,a7,a8,a9,a10,baomi,a11,a12, fw,a13,$('HidIP').value).value;
        
        if(bRet == "1"){
            location.href="Default.aspx";
        }
        else{
             alert(bRet);
        }
            // 調用後臺的代碼 寫入數據庫
        }
        function initPage(){
            for(var i=0;i<ns.length;i++){
                $("Tex" + ns[i]).value = "";
            }
        }


說明:
 
如下是代碼的應用,請參考:
 
<asp:TextBox ID= "TexPassword" runat= "server" BorderStyle= "Groove" MaxLength= "16"  onfocus= "inputfocus('Password',1)" onkeyup= "checkPwd(this.value);" onblur= "checkPwd(this.value);"
                            TextMode= "Password" Width= "150px"></asp:TextBox>


<asp:TextBox ID= "TexPassw" runat= "server" BorderStyle= "Groove" MaxLength= "16" onfocus= "inputfocus('Passw',2)" onkeyup= "checkPwd2(this.value);" onblur= "checkPwd2(this.value);" Width= "150px" TextMode= "Password"></asp:TextBox>.........................................................
 
若是支持本博文,請勞煩動動鼠標,點下下面的廣告 ,綠色無公害,請放心點擊:):):)
相關文章
相關標籤/搜索
每日一句
    每一个你不满意的现在,都有一个你没有努力的曾经。
本站公眾號
   歡迎關注本站公眾號,獲取更多信息