jQuery: clone elements AND events

前端 未结 4 1743
野的像风
野的像风 2021-01-01 17:19

Whenever I use ajax to dynamically create new content, .clone(), append() etc, the new element looses any triggers and events I programmed =(

After making copy, simp

4条回答
  •  走了就别回头了
    2021-01-01 17:56

    I finally got the UI datepicker to work properly. I had to completely remove datepicker BEFORE cloning and add it AFTER cloning elements. The guys at UI should make it easier for us. Go figure!

    Just before cloning:

    //#datepicker
    $("input[name='date']").datepicker( "destroy" );
    $("input[name='date']").removeClass("hasDatepicker").removeAttr('id');
    

    After cloning:

    $("input[name='date']").datepicker({ dateFormat: 'yy-mm-dd', changeMonth: true, changeYear: true, numberOfMonths: 3, showButtonPanel: true});
    

提交回复
热议问题