這是我的問題。看起來datapicker在第一次點擊動態添加的輸入時不會顯示(我必須點擊兩次或更多次,或者如果我點擊輸入(標籤區域)上方最好),沒有人看到問題。我嘗試了很多live(),bind().hasDatapicker和#datep1變體。如果可能,先測試你的答案。謝謝。爲什麼jquery datapicker不一致顯示?
腳本的一面:
<script>
$(document).ready(function(){
var div_data='<div id="div_data" class="data"><br />'+
'Dates from: <input type="text" id="datep1" size="10" name="data1">'+
' to: <input type="text" id="datep2" size="10" name="data2"> (Optional fields)</div>';
$("#rod_sem").after(div_data);
$(".br1").remove();
$(":input[name='pasirink']").click(function(){
var currentId = $(this).attr("id");
if (currentId == 'rod_sem')
{
$(".br1").remove();
$(".data").remove(); // this is done to prevent repetitive additions
$("#rod_sem").after(div_data); // here comes datepicker input
$("#datep1").live("click", function() {
$("#datep1").datepicker();
})
}
})
})
</script>
HTML:
<label id="la_rod_sem" for="rod_sem">Seminars</label>
<input type="radio" name="pasirink" id="rod_sem" value="rod_sem" checked="checked" />
<br class="br1" />
<br class="br1" />
<label id="la_rod_klaus" for="rod_klaus">Attendees</label>
<input type="radio" name="pasirink" id="rod_klaus" value="rod_klaus" />
<br />
<br />
'live'已被棄用了一段時間,使用'on'代替。這不是這個問題。 – 2013-06-28 04:14:45