我有一个jQuery日期选取器字段,当用户点击一个Add
按钮时,我正在克隆它。 我希望日期选取器出现在屏幕上随后添加的字段中。现在日期选择器仅出现在第一个字段中,并且not for the added/cloned fields
。jquery datepicker不适用于克隆元素
在检查了很多关于类似主题的帖子之后,我在这个阶段能够达到。 以下是我的代码到目前为止。
<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();
});
感谢。
你为什么要删除hasDatepicker类? –
早得早,我没有删除它。但在这里阅读http://stackoverflow.com/questions/5788999/jquery-datepicker-on-cloned-elements ..所以尝试这样做也 – DarkKnightFan