DatePicker仅显示一次动态内容



在用动态内容实例化datepicker时,我会遇到一个奇怪的问题。设置:带有PHP注入的HTML,与JQuery和Ajax一起编程。

我有jquery.ui.datepicker.mobile.js运行。

当我单击链接时,它会尽可能加载页面。当我返回并再次单击链接时,datePicker不会显示(输入字段确实具有'HasdatePicker'类)。

现在,我注意到如果我在另一个页面上,请转到链接的页面,然后单击它,它不会显示datepicker,甚至不是第一次。

$('.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;

有帮助吗?

在初始化新的datepicker字段(或所有当前)datepicker字段上尝试$(...).datepicker('destroy');

最新更新