jQuery datepicker minDate variable

前端 未结 3 836
暖寄归人
暖寄归人 2020-12-16 03:37

I\'m usung the jQuery datepicker. In my \"EndDate\" textbox I\'d like to use the date selected from the the \"StartDate\" textbox + 1. How do I do this?

I tried this

3条回答
  •  情话喂你
    2020-12-16 04:03

    You'll need to set the min date dynamically on the change event of the start date.

    Something like:

    $("#startDate").change(function() {
        test = $(this).datepicker('getDate');
        testm = new Date(test.getTime());
        testm.setDate(testm.getDate() + 1);
    
        $("#endDate").datepicker("option", "minDate", testm);
    });
    

    Answer to the edit:

    You cannot do the following:

    var test;
    $("#myinput").datepicker({
        onSelect: function() { test = $(this).datepicker("getdate"); }
    });
    $("#myotherinput").datepicker({
        minDate: test
    });
    

    Test is uninitialized at the time that minDate is being set on myotherinput. The process of setting the minDate doubtless requires DOM manipulation which datepicker manages on initialization or when "option" is called. Simply changing the variable that was used for initialization does not effect the already initialized datepicker.

提交回复
热议问题