與動態內容實例日期選擇器,當我遇到一個奇怪的問題顯示一次。 設置:使用PHP注入的HTML,與jQuery和AJAX一起編程。日期選擇器只能在動態內容
我有jquery.ui.datepicker.mobile.js運行。
當我點擊一個鏈接,它加載的頁面,因爲它應該。當我返回並再次單擊該鏈接時,datepicker不顯示(輸入字段確實具有'hasDatepicker'類)。現在
,我發現,如果我在另一頁上,轉到頁與鏈接,然後單擊它,它不顯示的日期選擇器,甚至不是第一次了。
$('.productSaleLink').live('click',function() {
var prod = $(this).attr('data-params');
$.post("product.php",{product:prod}, function(data){
$('#productContent').html(data);
$.mobile.changePage('#productsale', {transition: 'slide'});
$('.currentProduct').listview();
$('.sellLink').button();
$(':input').textinput();
$('.date').datepicker().css({'background-color':'red'});
});
return false;
})
product.php:
$html = "<ul class='currentProduct' data-role='listview' data-theme='d' data-divider-theme='d'>";
while($row2 = mysql_fetch_array($products))
{
$html .= "<li class='lis'>";
$html .= "<h3>".$row2['brand']." ".$row2['product']."</h3>";
$html .= "<p><span style='color:#666'>Serial:</span> <span style='font-weight:bold;'>".$row2['serial']."</span>,<span style='color:#666'> Product-ID:</span> ".$row2['product_id']."</p>";
$html .= "<p><span style='color:#666'>Bought:</span> ".$row2['buying_date']."<span style='color:#666'> From:</span> <span style='font-weight:bold;'>".$row2['seller']."</span></p>";
$html .= "<input class='client' style='display:inline;margin-right:5px;' type='text' name='client' id='client' value='Client' onfocus='if($(this).val()==\"Client\")$(this).val(\"\");' onblur='if($(this).val()==\"\")$(this).val(\"Client\");' />";
$html .= "<input class='date' style='display:inline;' type='date' name='date' id='".$row2['id']."' value='Date' />";
$html .= "<p class='ui-li-aside'>";
$html .= "<a class='sellLink' data-params='".$row2['id']."&3p&".$_SESSION['username']."' href='sell.php' data-role='button' data-inline='true' data-theme='a'>Sell</a>";
$html .= "</p>";
$html .= "</li>";
}
$html .= "</ul>";
echo $html;
任何幫助嗎?
用螢火蟲調試。你可以看到hasDatepicker類是否有效或無效 –