我有以下代碼JQuery的日期選擇器
<html>
<head>
//included all jquery related stuff ..not shown here
</head>
<body>
<button id = 'btn' />
<div id = 'ct'>
<?php echo file_get_contents('my_ajax_stuff.php'); ?>
</div>
</body>
<script>
$('.datepicker').datepicker({dateFormat: "dd-mm-yy"});
$('#btn').click(function() {
$.ajax({
type: "GET",
url: "my_ajax_stuff.php" ,
success: function(response) {
$('#ct').html(response);
/*added following line to solve this issue ..but not worked*/
//$(".datepicker").datepicker({dateFormat: "dd-mm-yy"});
} ,
error: function() {
$('#ct').html("Some problem fetching data.Please try again");
}
});
});
</script>
</html>
頁
my_ajax_stuff.php
包含一流的jQuery UI的日期選擇器= '日期選擇器' 。當第一次加載datepicker的作品。但當我點擊按鈕重新加載它,內容被替換爲新內容。但datepicker不工作。正如你所見,將日期選擇器放在ajax成功處理程序中。但它也失敗了。問題是什麼。它如何解決?
我已經試過了,這是在阿賈克斯成功處理程序評論here..But沒有區別 –
什麼給你的成功回調:'$(「.datepicker」)。長度?控制檯中有任何錯誤?順便說一句,你可以通過在mouseenter上需要(尚未完成)重新初始化datepicker來使用解決方法。 Mouseenter應該被授權 –
.length返回1.請在控制檯 –