【问题标题】:Datepicker only shows once in dynamic contentDatepicker 仅在动态内容中显示一次
【发布时间】:2012-10-17 12:46:40
【问题描述】:

我在使用动态内容实例化 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;

有什么帮助吗?

【问题讨论】:

  • 用 firebug 调试。你能看到 hasDatepicker 类是活跃还是不活跃

标签: php jquery jquery-mobile datepicker


【解决方案1】:

在初始化新字段之前,在所有(或所有当前)日期选择器字段上尝试$(...).datepicker('destroy');

【讨论】:

  • TypeError: inst is undefined inst.append.remove();
  • 您是否将问题上传到我们可以看到的地方?
  • 您可以在此处查看:blinkblink.eu/tests 登录并进行测试测试。然后点击一个产品,然后你会看到日期输入框(第一次)
  • 尝试将您的日期选择器调用移至$.post({...}).complete(function() { [destroy all and initialize new datepicker stuff] });
  • 另外,您的日期选择器字段中有一个默认值“日期”,请尝试删除它。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-04-14
  • 1970-01-01
  • 2018-06-14
  • 2012-08-24
  • 2015-04-12
  • 2017-05-27
  • 2011-09-27
相关资源
最近更新 更多