How do I set Min Date in Datepicker from another Datepicker?

后端 未结 2 976
故里飘歌
故里飘歌 2021-01-06 06:20

I am currently adding validation to my date pickers and am having trouble setting the min date in the to date picker to be whatever was chosen in the

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-06 06:32

    The answer is good but you need to destroy the datepicker of the $to because if not the $to datepicker have still the first date what you select, and remove the option in $to datepicker, this work for me, you not need to make other function for $to.

    $("#from").datepicker({
        defaultDate: new Date(),
        minDate: new Date(),
        onSelect: function(dateStr) 
        {         
            $("#to").datepicker("destroy");
            $("#to").val(dateStr);
            $("#to").datepicker({ minDate: new Date(dateStr)})
        }
    });
    

提交回复
热议问题