2016-05-16 51 views

回答

0

作为日历设置的一部分,您可以使用disableFunc选项定义禁用日期。以下将禁用今天日期之前的所有日期,因此您只需检查下午5点是否已过,并将1天添加到now变量。别忘了javascript为日期字段使用零索引,因此17:00的时间将是16小时,例如;

Calendar.setup({ 
        inputField : 'deliverydate', 
        ifFormat : '%d-%m-%Y', 
        button : 'cal_image', 
        align : 'Bl', 
        singleClick : true, 
        disableFunc : function(date) { 
         var now = new Date(); 
         if(now.getHours() > 16) { now.setDate(now.getDate() + 1); } 
       if(date.getFullYear() < now.getFullYear()) { return true; } 
       if(date.getFullYear() == now.getFullYear()) { if(date.getMonth() < now.getMonth()) { return true; } } 
       if(date.getMonth()  == now.getMonth())  { if(date.getDate()  < now.getDate()) { return true; } } 
       } 
       }); 
+0

我试过代码,但不工作即将错误HILITE日未定义HILITE选择 – Logic

+0

可以宥与更新你的问题正是你”到目前为止。 – PixieMedia

1

嗨,你可以使用下面的代码

<link rel="stylesheet" href="https://code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css"> 
     <script src="https://code.jquery.com/jquery-1.10.2.js"></script> 
     <script src="https://code.jquery.com/ui/1.11.2/jquery-ui.js"></script> 
      <script> 
      $a = $.noConflict(); 
      $a(function() { 

       var date = new Date(); 
       var currHour = date.getHours(); 
       if(currHour >= 17){ 
        var nextDate = (date.getDate() + 1)+"-"+date.getMonth()+"-"+date.getYear(); 
        $a("#date").datepicker({minDate : 1, dateFormat: "dd-M-yy", changeMonth: true, changeYear: true}); 
       }else{ 
        $a("#date").datepicker({minDate : 0, dateFormat: "dd-M-yy", changeMonth: true, changeYear: true}); 
       } 
      }); 
      function time_change(){ 
       var date_of = document.getElementById('date').value; 
       var d = new Date(date_of); 
       var day = d.getDate(); 
       var month = d.getMonth() + 1; 
       var year = d.getFullYear(); 
       var dt = new Date(); 
       var currDay = parseInt(dt.getDate()); 
       var time = parseInt(dt.getHours()); 
       if(day > currDay){ 
        options ='<option value="11:00">11 AM</option>'; 
        options +='<option value="12:00">12 PM</option>'; 
        options +='<option value="13:00">01 PM</option>'; 
        options +='<option value="14:00">02 PM</option>'; 
        options +='<option value="15:00">03 PM</option>'; 
        options +='<option value="16:00">04 PM</option>'; 
        options +='<option value="17:00">05 PM</option>'; 
        options +='<option value="18:00">06 PM</option>'; 
        options +='<option value="19:00">07 PM</option>'; 
        options +='<option value="20:00">08 PM</option>'; 
        jQuery("#delivery_instruction").html(options); 
       } 
       else if(time >= 8 && time < 17){ 
        var hour = time+3; 
        var options=""; 
        while(hour<=20){ 
         if(hour>=13){ 
          if(hour==13) 
           options +='<option value="'+hour+':00">01 PM</option>'; 
          if(hour==14) 
           options +='<option value="'+hour+':00">02 PM</option>'; 
          if(hour==15) 
           options +='<option value="'+hour+':00">03 PM</option>'; 
          if(hour==16) 
           options +='<option value="'+hour+':00">04 PM</option>'; 
          if(hour==17) 
           options +='<option value="'+hour+':00">05 PM</option>'; 
          if(hour==18) 
           options +='<option value="'+hour+':00">06 PM</option>'; 
          if(hour==19) 
           options +='<option value="'+hour+':00">07 PM</option>'; 
          if(hour==20) 
           options +='<option value="'+hour+':00">08 PM</option>'; 


         }else{ 
          if(hour<=12){ 
           options +='<option value="'+hour+':00">'+hour+' PM</option>'; 

          } 
         } 
         hour++; 
        } 
        jQuery("#delivery_instruction").html(options); 

       }else if(time >= 17){ 
        options ='<option value="11:00">11 AM</option>'; 
        options +='<option value="12:00">12 PM</option>'; 
        options +='<option value="13:00">01 PM</option>'; 
        options +='<option value="14:00">02 PM</option>'; 
        options +='<option value="15:00">03 PM</option>'; 
        options +='<option value="16:00">04 PM</option>'; 
        options +='<option value="17:00">05 PM</option>'; 
        options +='<option value="18:00">06 PM</option>'; 
        options +='<option value="19:00">07 PM</option>'; 
        options +='<option value="20:00">08 PM</option>'; 
        jQuery("#delivery_instruction").html(options); 
       } 
      } 
      </script> 
      <input type="text" name="date" onchange="time_change()" class="input-text required-entry" id="date"> 
      <select name="delivery_instruction" id="delivery_instruction" class="input-text required-entry getTime"></select> 

做工精细http://darktemptations.in/