Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

 $(function() {

$( "#arrival" ).datepicker({

dateFormat: "dd/mm/yy", 
changeMonth: true,
changeYear: true,
numberOfMonths: 1,
yearRange: ":2016",
minDate: "dateToday",


onClose: function( selectedDate ) {
$( "#departure" ).datepicker( "option", "minDate", selectedDate);
}

});
$(function() {
    $("#arrival").datepicker("setDate", "0");
});


$( "#departure" ).datepicker({

dateFormat: "dd/mm/yy", 
changeMonth: true,
changeYear: true,
numberOfMonths: 2,
yearRange: ":2016",

});

$(function() {
    $("#departure").datepicker("setDate", "1");
});

});

I have customized the datepicker and it works fine.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
366 views
Welcome To Ask or Share your Answers For Others

1 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...