小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

時間輸入的校驗(yàn) - - ItEye技術(shù)網(wǎng)站

 旭龍 2011-04-13
  1. <html>   
  2. <head>   
  3.     <title>時間輸入的校驗(yàn)--包子劍客</title>   
  4.     <!-- 2009.12.12 包子劍客 廣州-->   
  5. </head>   
  6. <body>   
  7.             時間輸入的校驗(yàn)<br/>   
  8.             請輸入時間:           <br/>   
  9.           <input type="text" onblur="isTimeFormat(this)" onkeyup="verify(this)" onkeypress="return inputNumber(event,this);"  title="時間格式:00:00"/>   
  10.           <br/>   
  11. </body>   
  12. </html>   
  13.   
  14. <script>   
  15.    //以下是時間的顯示相關(guān)函數(shù)   
  16.    function isTimeFormat(str) {   
  17.       var a = str.value.match(/^([0-2][0-9]):([w0-5][0-9])$/);   
  18.       if (a == null) {   
  19.          alert("時間格式不對,已經(jīng)被自動修正,請留意。");   
  20.          var length=str.value.length;   
  21.          if (length==1) {str.value="0" + str.value +":00";}   
  22.          else if (length==2) {str.value+=":00";}   
  23.          else if (length==3) {str.value+="00";}   
  24.          else if (length==4) {str.value+="0";}   
  25.          else {str.value="00:00";}   
  26.          str.select();   
  27.          return false;   
  28.       }   
  29.       return true;   
  30.    }      
  31.    //格式化時間格式   
  32.    function verify(text){   
  33.     var hour;   
  34.     var minute;   
  35.     var tmp;   
  36.     var index;   
  37.     var textValue = text.value;   
  38.     if(textValue.length == 1 ) {   
  39.       if (textValue == ":"){text.value = "00:"; }   
  40.       return true;   
  41.     }   
  42.     if(textValue.length == 2 ) {   
  43.       if (!isNum(textValue)) text.value = "0" + textValue;   
  44.       return true;   
  45.     }   
  46.     if(textValue.length > 2){ //當(dāng)長度超過2時,進(jìn)行處理   
  47.         hour = textValue.substr(0,2); //取前兩位數(shù)字,即小時   
  48.         if(!isNum(hour)){//不是數(shù)字   
  49.             text.value = '00';   
  50.             return;   
  51.         }   
  52.         if(hour < 24){ //10<x<24   
  53.            text.value = hour + ':';//顯示小時   
  54.            index = textValue.indexOf(':'); //定位冒號   
  55.            minute = index > 0 ? textValue.substr(index + 1,2) : textValue.substr(2,2);   
  56.            if(!isNum(minute)){//不是數(shù)字   
  57.                 text.value = hour + ':00';   
  58.                 return;   
  59.             }   
  60.            if(minute < 59){   
  61.             tmp = hour + ':' + minute;   
  62.            }else{   
  63.             tmp = hour + ':59';   
  64.            }   
  65.         }else//x>=24   
  66.            hour = '0' + textValue.substr(0,1);   
  67.            text.value = hour + ':' + text.value.substr(1,1);   
  68.            index = textValue.indexOf(':');   
  69.            minute = index > 0 ? textValue.substr(index + 1,2) : textValue.substr(1,2);   
  70.            if(!isNum(minute)){//不是數(shù)字   
  71.                 text.value = hour + ':00';   
  72.                 return;   
  73.             }   
  74.            if(minute < 59){   
  75.              tmp = hour + ':' + minute;   
  76.            }else{   
  77.              tmp = hour + ':59';   
  78.            }   
  79.         }   
  80.     text.value = tmp;//輸入“小時:分鐘”格式   
  81.     }   
  82.    }   
  83.    //只讓輸入數(shù)字和:   
  84.    function inputNumber(e,textValue){   
  85.     var keynum;   
  86.     var keychar;   
  87.     var numcheck;   
  88.     if(window.event) // IE   
  89.     {   
  90.         if(58==e.keyCode) {return true;}   
  91.         keynum = e.keyCode   
  92.     }else if(e.which) // Netscape/Firefox/Opera   
  93.     {   
  94.         keynum = e.which   
  95.     }   
  96.     keychar = String.fromCharCode(keynum);   
  97.     return isNum(keychar);   
  98.    }   
  99.    //是否為數(shù)字   
  100.    function isNum(str){   
  101.     if(""==str){   
  102.       return true;   
  103.     }   
  104.     var reg = /\D/;    
  105.     return str.match(reg)==null;   
  106.    }   
  107.    //以上是時間的顯示相關(guān)函數(shù)   
  108. </script>  

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約