problem when cloning jQuery UI datepicker

后端 未结 12 1619
谎友^
谎友^ 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:06

    $('input.datefield').datepicker("destroy");
    $('input.datefield').datepicker();
    

    it works good. But just doing this, datepicker will open on cloned input and set the date to the original input (because they have the same ID)

    to solve this you must change id attribute of the cloned input.

    dp = < cloned input >
    var d = $('input.vDateField');
    dp.removeClass('hasDatepicker');
    dp.attr('id', dp.attr('id')+d.length);
    d.datepicker("destroy");
    d.datepicker();
    

    and it will work great!

提交回复
热议问题