JQuery datepicker not working after ajax call

后端 未结 5 1608
一向
一向 2021-01-18 09:57

I have the following code


    
       //included all jquery related stuff ..not shown here
    
    
               


        
5条回答
  •  清歌不尽
    2021-01-18 10:46

    The answer you are looking for may be similar to this question: jQuery datepicker won't work on a AJAX added html element

    You're replacing the datepicker element in the DOM with the ajax response. The reason this works for the first time is that PHP renders the my_ajax_stuff.php on first load already in the HTML so it becomes available to jQuery in the DOM.

    // do this once the DOM's available...
    $(function(){
    
    // this line will add an event handler to the selected inputs, both
    // current and future, whenever they are clicked...
    // this is delegation at work, and you can use any containing element
    // you like - I just used the "body" tag for convenience...
        $("body").on("click", ".datepicker", function(){
                $(this).datepicker();
                $(this).datepicker("show");
        });
    });
    

提交回复
热议问题