jquery datetime picker set minDate dynamic

前端 未结 9 1179
野趣味
野趣味 2020-11-29 11:12

I guys i\'m using a datetimepicker by trentrichardson.com.

I have a form with two input fields : from and to and i want to be able

9条回答
  •  孤城傲影
    2020-11-29 11:31

    luca: A small addition to your answer...

    Using the function you suggested the time component is ignored the first time the datetimepicker is displayed. If you close the datetimepicker and reopen it again, the time component mysteriously reappears. I'm not quite sure what is causing this, but it can be fixed with a bit of a hack:

    function setMinMaxDate ( element )
    {
        // Store current date - setting max/min date seems to destroy time component
        var val = $(element).val();
    
        if (element.id == 'endDate') 
        {     
            var x=$('#startDate').datetimepicker("getDate");
            $( element ).datetimepicker( "option", "minDate",x ); 
        } 
        else if (element.id == 'startDate') 
        {     
            var x=$('#endDate').datetimepicker("getDate");
            $( element ).datetimepicker( "option", "maxDate",x ); 
        }
    
        // Restore date
        $(element).val(val);
    }
    

提交回复
热议问题