laydate組件選擇時間段的判斷

前言:spa

在使用laydate組件的時候,不免會遇到選擇時間段,官網給的文檔中有選擇時間段的組件,可是並很差用,首先只能選擇一個月的時間段,有侷限性,其次精確到時間的話要先選日期範圍再選時間範圍,很變態,仍是用兩個組件比較合適,可是用兩個組件的話須要作判斷,由於起始時間確定不能在結束時間以後,反之亦然,本文記錄的是如何解決這一判斷。3d

效果圖:code

一、官網給的效果:blog

二、須要實現的效果:文檔

假設起始時間以下:io

在起始時間以前的時間皆爲灰色不可選狀態:function

參考代碼:class

var time_start =laydate.render({
  elem : '#beginTime',
  type : 'datetime',
  done: function(value,date, endDate) {
    time_end.config.min = {
      year: date.year,
      month: date.month - 1,
      date: date.date,
      hours: date.hours,
      minutes: date.minutes,
      seconds: data.seconds
    }
    if(compareDate(value,$("#endTime").val()))  {
      $("#endTime").val("");
    }
  }
});
var time_end = laydate.render({   elem : '#endTime',   type : 'datetime',   done: function(value,date, endDate) {     time_start.config.max = {       year: date.year,       month: date.month - 1,       date: date.date,       hours: date.hours,       minutes: date.minutes,       seconds: data.seconds     }     if(compareDate($("#beginTime").val(),value)) {       $("#beginTime").val("");     }   } });
function compareDate(d1,d2){
  return ((new Date(d1.replace(/-/g,"\/"))) >  (new Date(d2.replace(/-/g,"\/"))));
}
相關文章
相關標籤/搜索