problem when cloning jQuery UI datepicker

后端 未结 12 1611
谎友^
谎友^ 2020-11-29 05:36

I have a div in which there is a datepicker. I use something like this to clone it:

mydiv = $(\'#someDiv\');

// works fine so far
mydiv.find(\'input.datefie         


        
12条回答
  •  既然无缘
    2020-11-29 06:07

    Here how it worked for me:

    First you need to remove the class hasDatepickerfrom the cloned elements,because this is what is preventing the datepicker from getting attached to the specific element.

    Then you gotta remove the id attribute from each of the cloned elements else .datepicker() will assume that datepicker is added to this element.

    After that call .datepicker() on cloned element.

    newDiv.find('.classAttributeGivenForDatepicker').each(function() {
       $(this).removeAttr('id').removeClass('hasDatepicker');
       $(this).datepicker({dateFormat: 'dd-mm-yy', minDate: 0, autoclose: true,});
    });
    

提交回复
热议问题