我的jquery datepicker在动态输入字段中不能很好地工作,当我单击第一个字段添加按钮时,datepicker正常工作,然后是第二个,第三个,....它不起作用。有人可以帮我解决问题吗?感谢。
这是javascript
var MaxInputs = 8;
var InputsWrapperRates = $("#InputsWrapperRates");
var AddButtonRates = $("#AddMoreFileBoxRates");
var z = InputsWrapperRates.length;
var FieldCountRates = 0;
$(AddButtonRates).click(function (e) {
if(z <= MaxInputs) {
FieldCountRates++;
var block = $('<div class=textWrap><input class="smaller" type="text" name="season[]" id="field_'+ FieldCountRates +'" placeholder="Season '+ FieldCountRates +'"/><input class="smaller" type="text" name="stay[]" id="field_'+ FieldCountRates +'" placeholder="Minimum Stay '+ FieldCountRates +'"/><input class="smaller" type="text" name="date1[]" id="field_'+ FieldCountRates +'" data-field="date" placeholder="From date 1" readonly/><input class="smaller" type="text" name="date2[]" id="field_'+ FieldCountRates +'" data-field="date" placeholder="To date 1" readonly/><input class="smaller" type="text" name="date3[]" id="field_'+ FieldCountRates +'" data-field="date" placeholder="From date 2" readonly/><input class="smaller" type="text" name="date4[]" id="field_'+ FieldCountRates +'" data-field="date" placeholder="To date 2" readonly /><a href="#" class="removeclassRates">×</a><div class="dtBox'+z+'"></div></div>')
$(InputsWrapperRates).append(block);
$("#dtBox"+z).DateTimePicker();
z++;
}
return false;
});
这是html
<div id="InputsWrapperRates">
<button id="AddMoreFileBoxRates">Add Villa Rates</button>
<div id="dtBox"></div>
</div>