2016-09-07 20 views
0

1个月范围的日期将在过去的日期1个月范围日期过去将工作日期jQuery UI的

例如

工作将来日期将禁用(#to_date)

https://jsfiddle.net/swaroop206/vpe54c29/4/

$(document).ready(function(){ 
$('#from_date').datepicker({ 
     changeMonth: true, 
     changeYear: true, 
     dateFormat: "yy-mm-dd", 
     maxDate: new Date(), 

     onSelect: function (selectedDate) { 
       var orginalDate = new Date(selectedDate); 
       var monthsAddedDate = new Date(new Date(orginalDate).setMonth(orginalDate.getMonth() + 1)); 

       $("#to_date").datepicker("option", 'minDate', selectedDate); 
       $("#to_date").datepicker("option", 'maxDate', monthsAddedDate); 
      } 
    }).click(function(){ 
     $('.ui-datepicker-calendar').show(); 
    }); 
    $('#to_date').datepicker({ 
     changeMonth: true, 
     changeYear: true, 
     dateFormat: "yy-mm-dd", 
     maxDate: new Date(), 

     onSelect: function (selectedDate) { 
       var orginalDate = new Date(selectedDate); 
       var monthsAddedDate = new Date(new Date(orginalDate).setMonth(orginalDate.getMonth() - 1)); 

       $("#from_date").datepicker("option", 'minDate', monthsAddedDate); 
       $("#from_date").datepicker("option", 'maxDate', selectedDate); 
      } 
    }).click(function(){ 
     $('.ui-datepicker-calendar').show(); 
    }); 
}); 
</script> 
+0

你想要什么输出? – Amy

+0

意思是如果你选择5月9日。那么在第6个日期的日期中将被禁用。 – Amy

+0

查看我更新的答案。 – Amy

回答

0

其实你正在使用datetimepicker用于改变运行时的选项。您应该使用datepicker函数。

更改此:

$("#to_date").datetimepicker("option", 'minDate', selectedDate); 
    $("#to_date").datetimepicker("option", 'maxDate', monthsAddedDate); 

TO

$("#to_date").datepicker("option", 'minDate', selectedDate); 
    $("#to_date").datepicker("option", 'maxDate', monthsAddedDate);