wdatepicker 日历控件,起始日期和结束日期 ,相差60天,并且在当时时间之前

时间:2021-09-08 18:05:54

官方地址:http://www.my97.net/dp/index.asp


开始时间和结束时间的最大间隔为60天,并且不大于当前时间


查询了官方文档demo,发现可以满足"开始时间和结束时间的最大间隔为60天"条件,但是不满足并且不大于当前时间。


在网上查了一些例子:自己应用步骤如下 :(前提是已经引入WdatePicker.js)


 <div class="span9 content-right" style="padding: 0 20px;">
<div class="row-fluid search-bar" id="search-bar">
   <form class="form-inline" style="margin-left: 170px">
       <div class="datetime-group">
   <label class="control-label" for="terminalManagement_brand">开始时间:</label>
  <div class="input-append date">
    <input name="startTime" id="d4311" class="Wdate" type="text"  onfocus="WdatePicker({skin:'whyGreen',maxDate:'%y-%M-{%d-1}',dateFmt:'yyyy-MM-dd',readOnly:true,isShowToday:false})"/>
 </div>
 </div>
 <div class="datetime-group">
   <label class="control-label" for="terminalManagement_model" style="text-align:left;width:60px">结束时间:</label>
   <div class="input-append date" style="padding:0px">
     <input name="endTime" id="d4312" class="Wdate" type="text" onFocus="endTimeFocus()"/>
   </div>
 </div>


页面JS写法如下:

<script>
  function endTimeFocus() {
    return WdatePicker({
      skin : 'whyGreen',
      minDate:'#F{$dp.$D(\'d4311\')}',
      //maxDate : '#F{$dp.$D(\'startTime\',{d:30})||\'%y-%M-%d\'}',
      maxDate:getMaxDate(),
      dateFmt:'yyyy-MM-dd',
      readOnly:true,
      isShowToday:false
    });
  }
  //获得最大时间
  function getMaxDate(){
    var clock=currentTime();
    var dt;
    var times=0;
    dt=$("#d4311").val();
    if(dt!=''){
      times =Date.parse(dt.replace(/-/g,'/'))+60*24*60*60*1000;//时间间隔为60天
      if(times-Date.parse(clock.replace(/-/g,'/'))<0){
        var d1 = new Date(times);
        var year = d1.getFullYear();
        var month = d1.getMonth() + 1;    //月份以0开头
        var day = d1.getDate();
        var hh = d1.getHours();
        var mm = d1.getMinutes();
        var clock = year + "-";
        if (month < 10) clock += "0";
        clock += month + "-";
        if (day < 10) clock += "0";
        clock += day + " ";
        if (hh < 10) clock += "0";
        clock += hh + ":";
        if (mm < 10) clock += '0';
        clock += mm;
      }
    }
    return clock;
  }

  //当前时间(如果当前时间前一就,在day变量后减一天或者加一天等)
  function currentTime() {
    var now = new Date();
    var year = now.getFullYear();
    var month = now.getMonth() + 1;
    var day = now.getDate();
    var hh = now.getHours();
    var mm = now.getMinutes();
    var clock = year + "-";
    if (month < 10)  clock += "0";
    clock += month + "-";
    if (day < 10) clock += "0";
    clock += day + " ";
    if (hh < 10)  clock += "0";
    clock += hh + ":";
    if (mm < 10) clock += '0';
    clock += mm;
    return (clock);
  }

</script>