Changing minDate and maxDate on the fly using jQuery DatePicker

前端 未结 5 1623
无人共我
无人共我 2020-11-28 12:12

I\'m having a particular issue with the jQuery Datepicker. I can easily add a date range, but I want the selectable range to change depending on the event the user has picke

5条回答
  •  天涯浪人
    2020-11-28 12:33

    You have a couple of options...

    1) You need to call the destroy() method not remove() so...

    $('#date').datepicker('destroy');
    

    Then call your method to recreate the datepicker object.

    2) You can update the property of the existing object via

    $('#date').datepicker('option', 'minDate', new Date(startDate));
    $('#date').datepicker('option', 'maxDate', new Date(endDate));
    

    or...

    $('#date').datepicker('option', { minDate: new Date(startDate),
                                      maxDate: new Date(endDate) });
    

提交回复
热议问题