0

動的コンテンツで Datepicker をインスタンス化するときに奇妙な問題が発生します。セットアップ: jQuery および AJAX と一緒にプログラムされた、PHP インジェクションを含む HTML。

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;

何か助けはありますか?

4

1 に答える 1

0

$(...).datepicker('destroy');新しいフィールドを初期化する前に、すべての (または現在のすべての) 日付ピッカー フィールドを試してください。

于 2012-10-17T13:06:20.080 に答える