Datepicker仅在动态内容中显示一次

时间:2012-10-17 12:46:41

标签: php jquery jquery-mobile datepicker

在使用动态内容实例化Datepicker时,我遇到了一个奇怪的问题。 设置:使用PHP注入的HTML,与jQuery和AJAX一起编程。

我已jquery.ui.datepicker.mobile.js正在运行。

当我点击链接时,它会按原样加载页面。当我返回并再次单击该链接时,日期选择器不显示(输入字段确实具有'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;

任何帮助?

1 个答案:

答案 0 :(得分:0)

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

相关问题