如何在TO日历上禁用以前的日期?

时间:2014-11-20 19:23:31

标签: javascript jquery jquery-ui-datepicker

这是我正在使用的脚本。要做些什么改变?

$( "#from" ).datepicker
  defaultDate: "+1w",
  changeMonth: true,
  numberOfMonths: 3,

$( "#to" ).datepicker
  defaultDate: "+1w",
  changeMonth: true,
  numberOfMonths: 3  

3 个答案:

答案 0 :(得分:0)

执行:

var today = new Date();
var yesterday = new Date(today.getFullYear(),today.getMonth(),today.getDate()-1)

然后在您的date picker function

中添加以下属性
minDate : yesterday

答案 1 :(得分:0)

我修好了: -

必须在$( "#from" ).datepicker

中添加此代码
onSelect: function( selectedDate ) {
  $( "#to" ).datepicker( "option", "maxDate", selectedDate 

必须在$( "#to" ).datepicker

中添加此代码
onSelect: function( selectedDate ) {
             $( "#toDateRange" ).datepicker( "option", "minDate", selectedDate

答案 2 :(得分:0)

这是完整的代码

 var dateToday = new Date();
     $(".datefrom" ).datepicker({
        dateFormat: 'dd/mm/yy',
         minDate: dateToday,

         onClose: function( selectedDate ) {
        $( ".dateto" ).datepicker( "option", "minDate", selectedDate );
      },
        onSelect: function(selectedDate) {
             var option = this.class == "datefrom" ? "minDate" : "maxDate",
              instance = $(this).data("datepicker"),
              date = $.datepicker.parseDate(instance.settings.dateFormat || $.datepicker._defaults.dateFormat, selectedDate, instance.settings);
         }
     });

$(".dateto" ).datepicker({
    dateFormat: 'dd/MM/yyyy',

    onClose: function( selectedDate ) {
        $( ".datefrom" ).datepicker( "option", "maxDate", selectedDate );
    }
  });


$('.datefrom,.dateto').change(selector)

它会从日历中禁用上一个日期,根据日历中的选择,日历将自动更新并禁用之前的日期..