Changing minDate and maxDate on the fly using jQuery DatePicker

前端 未结 5 1616
无人共我
无人共我 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:41

    For from / to date, here is how I implemented restricting the dates based on the date entered in the other datepicker. Works pretty good:

    function activateDatePickers() {
        $("#aDateFrom").datepicker({
            onClose: function() {
                $("#aDateTo").datepicker(
                        "change",
                        { minDate: new Date($('#aDateFrom').val()) }
                );
            }
        });
        $("#aDateTo").datepicker({
            onClose: function() {
                $("#aDateFrom").datepicker(
                        "change",
                        { maxDate: new Date($('#aDateTo').val()) }
                );
            }
        });
    }
    

提交回复
热议问题