jQuery DatePicker Min Max dates

前端 未结 6 1797
春和景丽
春和景丽 2020-12-07 01:22

I have the jQuery date picker setup and working but would like help with setting the minDate and maxDate options. My current code is below (without these options). How can

6条回答
  •  广开言路
    2020-12-07 02:04

    $(function() {
    
        $( "#datepicker" ).datepicker({ 
            changeYear: true,
            minDate: '-3M',
            maxDate: '+28D',
        });
    });
    

    JSFiddle Demo

    UPDATE

    You can calculate tour max and min valid dates from the default date, then assign it to the date picker.

    var expdisp = $("#expdisp").attr("value");
    
    $("#expirydate" ).datepicker({
        showOn: "button",
        buttonImage: "images/calendar.gif",
        buttonImageOnly: true,
        dateFormat: "dd/mm/yy",
        defaultDate: expdisp,
        showOtherMonths: true,
        selectOtherMonths: true,
        changeMonth: true,
        changeYear: true,
    
        minDate: '-3M',
        maxDate: '+28D',
    });
    

    Update Demo

提交回复
热议问题