我使用的是jQuery UI的這個jQuery函數生成一個日期選擇器當用戶點擊文本框一個:Jquery函數不適用於動態生成的表單組件?
<script>
$(function() {
var dates = $("#from, #to").datepicker({
defaultDate: "+1w",
changeMonth: true,
changeYear: true,
numberOfMonths: 1,
onSelect: function(selectedDate) {
var option = this.id == "from" ? "minDate" : "maxDate",
instance = $(this).data("datepicker"),
date = $.datepicker.parseDate(
instance.settings.dateFormat ||
$.datepicker._defaults.dateFormat,
selectedDate, instance.settings);
dates.not(this).datepicker("option", option, date);
}
});
});
</script>
正如你可以看到它的文本框從和迴應 。該文本框是在我的html代碼,如:
<div class="clearfix">
<label for="from">From</label>
<input type="text" id="from" name="from" class="xlarge"/>
</div>
<div class="clearfix">
<label for="to">to</label>
在這一點上一切正常。後來,在相同的形式讓用戶克隆使用這個其他代碼這種形式的元素:
$(document).ready(function() {
var removeButton = '<a href="#" id="remove">remove</a>';
$('#addl').click(function() {
$('div.jobitems:last').after($('div.jobitems:first').clone());
$('div.jobitems:last').append(removeButton);
$('div.jobitems:last input').each(function(){
this.value = '';
});
});
$('#remove').live('click', function() {
$(this).closest('div.jobitems').remove();
});
});
<input type="text" id="to" name="to" class="xlarge"/>
</div>
當用戶克隆的元素,將新的不來生成的日期選擇器功能響應。我對此很困惑。 在這裏,您可以查看運行的代碼:http://domingo.net46.net/example/reg.php
「您正在看到此頁面,因爲000webhost.com的系統管理員當前正在檢查本網站的惡意內容。」除此之外......嘗試在克隆時運行datepicker。 – Henry
首先,我會改變你的方法來尋找一個類。像上面這樣的克隆元素會導致具有相同ID的項目不是最佳實踐。 –