How to constrain min and max dates for jQuery-ui datepicker based on another date

后端 未结 1 1324
栀梦
栀梦 2021-01-07 14:36

I would like to know how can we set the check-out date between the check-in date. Like if we select the month of June (when current month is February) and the 15th day. So i

1条回答
  •  借酒劲吻你
    2021-01-07 15:04

    Have a look at this demo. I've added some lines in the onSelect event like so:

        onSelect: function(dateStr) {
            var d1 = $(this).datepicker("getDate");
            d1.setDate(d1.getDate() + 0); // change to + 1 if necessary
            var d2 = $(this).datepicker("getDate");
            d2.setDate(d2.getDate() + 30); // change to + 29 if necessary
            $("#to").datepicker("setDate", null);
            $("#to").datepicker("option", "minDate", d1);
            $("#to").datepicker("option", "maxDate", d2);
            datepicked();
        }
    

    According to my understanding of lodging business, the dates should be inclusive -- i.e. June/15/2012 + 30 nights should be June/14/2012. But I've followed the example you mentioned in the first few lines of question.

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