6

ユーザーがボタンをクリックしたときに複製するjquery日付ピッカーフィールドがありAddます。画面に後で追加されるフィールドに日付ピッカーを表示したい。現在、日付ピッカーは最初のフィールドと。にのみ表示されていますnot for the added/cloned fields

ここで同様のトピックに関する多くの投稿を確認した後、私はこの段階で到達することができました。以下はこれまでの私のコードです。

<div class="repeatingSection">
<a href="#" class="deleteDate" style="display: none;">-Delete</a>
<input type="text" class="dateListValues" style="position: relative; z-index:100000;" 
       id="dateListValues_1" size="15" />
</div>
<a href="#" class="addDate">+ Add</a>

JS:

// Add a new repeating section
$('.addDate').click(function(){
    var currentCount =  $('.repeatingSection').length;
    var newCount = currentCount+1;
    var newID;
    var lastRepeatingGroup = $('.repeatingSection').last();
    var newSection = lastRepeatingGroup.clone();
    newSection.insertAfter(lastRepeatingGroup);
    newSection.find("input").each(function (index, input) {
        input.id = input.id.replace("_" + currentCount, "_" + newCount);
        input.name = input.name.replace("_" + currentCount, "_" + newCount);
        input.value = "";
            //removing the additional hasDatepicker class 
        $('#'+input.id).removeClass('hasDatepicker');
    });

    return false;
});

   $('.dateListValues').each(function(){
    $(this).datepicker();
   });

ありがとう。

4

2 に答える 2

5

datepicker新しく作成された要素でプラグインを初期化する必要があります。次の行を の直前に追加してみてくださいreturn false;:

newSection.find(".dateListValues").datepicker();
于 2012-12-14T10:08:00.710 に答える
1

クリック機能内で日付ピッカーを初期化します。

$('.addDate').click(function(){
var currentCount =  $('.repeatingSection').length;
var newCount = currentCount+1;
var newID;
var lastRepeatingGroup = $('.repeatingSection').last();
var newSection = lastRepeatingGroup.clone();
newSection.insertAfter(lastRepeatingGroup);
newSection.find("input").each(function (index, input) {
    input.id = input.id.replace("_" + currentCount, "_" + newCount);
    input.name = input.name.replace("_" + currentCount, "_" + newCount);
    input.value = "";
        //removing the additional hasDatepicker class 
    $('#'+input.id).removeClass('hasDatepicker');

});
  newSection.find(".dateListValues").datepicker(); //here
  return false;
});
于 2012-12-14T10:10:05.380 に答える