jquery datepicker set date to tomorrow's date

后端 未结 1 677
无人共我
无人共我 2020-12-12 00:45

I have set the date for #arrival to todays date, but how can I set the #departure to tomorrow\'s date?

 $(function() {

$( \"#arrival\" ).datepicker({

dateF         


        
相关标签:
1条回答
  • 2020-12-12 01:23

    In the change function of the first datepicker, create a date object, set the date one day forward, and set the date of the second datepicker to that date. You can use minDate to make sure any date earlier than the set date can not be picked.

    $(function () {
        $("#arrival").datepicker({
            dateFormat: "dd/mm/yy",
            changeMonth: true,
            changeYear: true,
            numberOfMonths: 1,
            yearRange: ":2016",
            minDate: "dateToday",
            onClose: function (selectedDate) {
                var myDate = $(this).datepicker('getDate'); 
                    myDate.setDate(myDate.getDate()+1); 
                $('#departure').datepicker('setDate', myDate);
            }
        });
    
        $("#departure").datepicker({
            dateFormat: "dd/mm/yy",
            changeMonth: true,
            changeYear: true,
            numberOfMonths: 2,
            yearRange: ":2016",
        });
    
        $("#arrival").datepicker("setDate", "0");
        $("#departure").datepicker("setDate", "1");
    });
    

    FIDDLE

    0 讨论(0)
提交回复
热议问题