亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

純javascript判斷查詢?nèi)掌谑欠駷橛行掌?/h1>
 更新時(shí)間:2015年08月24日 11:02:12   作者:人界的游鬼  
很多網(wǎng)站都涉及到輸入日期選項(xiàng),如果客戶日期輸入錯(cuò)誤,可能導(dǎo)入查詢不到甚至查詢到錯(cuò)誤的信息,為了更好的滿足用戶需求,需要對(duì)日期進(jìn)行校驗(yàn),下面給大家介紹使用純javascript如何判斷查詢?nèi)掌谑欠駷橛行掌?,需要的朋友可以參考?/div>

以下內(nèi)容主要通過js代碼給大家介紹,代碼比較簡(jiǎn)單,包含注釋,有好的建議歡迎提出。

如下圖,當(dāng)查詢條件含有日期時(shí),如“2012-3-4”,查詢前校驗(yàn)輸入的日期字符串是否為有效的日期

var snapshot_createTime_begin=$(selector+" input[name='createTime_begin']").val().trim();
      var snapshot_createTime_end=$(selector +" input[name='createTime_end']").val().trim();
      try{
        //判斷開始時(shí)間是否為有效的日期
        if(snapshot_createTime_begin!=""&&new Date(snapshot_createTime_begin).getDate()!=snapshot_createTime_begin.match(/-\d{0,2}$/g)[0].replace(/-/g,"")){
          throw new Error();
        }
        //判斷結(jié)束時(shí)間是否為有效的日期
        if(snapshot_createTime_end!=""&&new Date(snapshot_createTime_end).getDate()!=snapshot_createTime_end.match(/-\d{0,2}$/g)[0].replace(/-/g,"")){
          throw new Error();
        }
        if(Date.parse(snapshot_createTime_begin)>Date.parse(snapshot_createTime_end)){
          //alert("開始日期不應(yīng)當(dāng)超過結(jié)束日期!");
          alert("開始日期不應(yīng)當(dāng)超過結(jié)束日期!");
          return ;
        }
        $.extend(pageObj,{
          createTimeBegin:snapshot_createTime_begin,
          createTimeEnd:snapshot_createTime_end,
        });
        initPagination();
      }catch(e){
        //alert("請(qǐng)輸入有效日期!")
        alert("請(qǐng)輸入有效日期!");
      }

js判斷年月日是否一個(gè)有效日期

function isdate(intYear,intMonth,intDay){ 
 if(isNaN(intYear)||isNaN(intMonth)||isNaN(intDay)) return false;   
 if(intMonth>12||intMonth<1) return false; 
 if ( intDay<1||intDay>31)return false; 
 if((intMonth==4||intMonth==6||intMonth==9||intMonth==11)&&(intDay>30)) return false; 
 if(intMonth==2){ 
   if(intDay>29) return false;  
   if((((intYear%100==0)&&(intYear%400!=0))||(intYear%4!=0))&&(intDay>28))return false; 
  }
 return true; 
}

以上代碼就是對(duì)日期的有效性校驗(yàn),希望對(duì)大家有所幫助。

相關(guān)文章

最新評(píng)論