DatePicker not working in ajax loaded page

后端 未结 3 969
深忆病人
深忆病人 2021-01-15 07:28

I attach the datepicker to inputs in a global script file with like this:

$(document).on(\"focusin\",\".datePick\", function () {
            $(this).datepic         


        
3条回答
  •  悲&欢浪女
    2021-01-15 08:14

    As mentioned in my comment on TJ VanToll's answer, as long as the parent element to which your trigger is bound is present at the time the DOM is loaded, you'll be fine.

    See this fiddle for an example.

    JS:

    $(function(){
        $(document).on("focusin",".datePick", function () {
           $(this).datepicker({
                dateFormat: "dd/mm/yy",
                changeMonth: true,
                changeYear: true,
                onClose: function () { $(this).valid(); }
            });
        });
    
        $('#focusin').append('');
    
    });​
    

    HTML:

    As long as your modal div is present on load, it should be able to capture your input after loading.

提交回复
热议问题