如何在第一天之前设置我的第二个日期选择器?

时间:2012-03-08 15:19:12

标签: javascript jquery

我有2个datepicker文本字段:其中一个是#from,另一个是#to。 现在,我的用户可以拥有#from和#to的相同日期。

如何让#to datepicker从#from + 1天开始?

这是我目前的代码:

   var dates = $( "#from, #to" ).datepicker({   
        numberOfMonths: 2,
        minDate: 0,
        onSelect: function( selectedDate ) {
            var option = this.id == "from" ? "minDate" : "maxDate",
                instance = $( this ).data( "datepicker" ),
                date = $.datepicker.parseDate(
                    instance.settings.dateFormat ||
                    $.datepicker._defaults.dateFormat,
                    selectedDate, instance.settings );
            dates.not( this ).datepicker( "option", option, date );
        }
    });

1 个答案:

答案 0 :(得分:2)

 var dates =$( "#from" ).datepicker({   
    numberOfMonths: 2,
    minDate: 0,
    onSelect: function( selectedDate ) {
        var option = this.id == "from" ? "minDate" : "maxDate",
            instance = $( this ).data( "datepicker" ),
            date = $.datepicker.parseDate(
                instance.settings.dateFormat ||
                $.datepicker._defaults.dateFormat,
                selectedDate, instance.settings );
        dates.not( this ).datepicker( "option", option, date );
        var month = date.getMonth() + 1;
        var toDate = (date.getDate()+1) + '/' + month + "/" + date.getFullYear();
       $( "#to").val(toDate);
    }
});