简体   繁体   中英

how to set the EndDate 2 weeks after StartDate in DatePicker

this is my code in jquery

jQuery.datepicker.setDefaults({
    showOn: 'both',
    prevText: 'Prev',
    nextText: 'Next',
    firstDay: 1,
    dateFormat: 'yy-mm-dd'
});
jQuery('.start-date').datepicker({
    onClose: function(selectedDate) {
        console.log('close start date');
        jQuery('.end-date').datepicker('option', 'minDate', selectedDate);
    }
});
jQuery('.end-date').datepicker({
    onClose: function(selectedDate) {
        console.log('close end date');
        jQuery('.start-date').datepicker('option', 'maxDate', selectedDate);
    }
});
jQuery('.future-date').datepicker();
jQuery('.future-date').datepicker('option', 'minDate', '0');
jQuery('.datepicker').datepicker('setDate', '0');

Try this

jQuery('.start-date').datepicker({
    onClose: function(selectedDate) {
        console.log('close start date');

        var inputString = jQuery('.start-date').val();
        var dString = inputString.split('-');

        var dt = new Date(dString[2], dString[1] - 1, dString[0]);
        dt.setDate(dt.getDate() + 14);

        var finalDate = dt.GetDate() + "-" + (dt.GetMonth() + 1) + "-" + dt.GetYear();
        jQuery('.end-date').val(finalDate);
    }
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM