【问题标题】:Re-initialize all elements of Jquery Mobile after ajax Request?ajax请求后重新初始化Jquery Mobile的所有元素?
【发布时间】:2014-02-27 13:03:33
【问题描述】:

我有以下页面,

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link rel="stylesheet" href="<%= ResolveUrl("~/css/jquery.mobile-1.3.0.min.css") %>" />
</head>
<body>
    <form id="form1" runat="server">
    <div>  
         <div data-role="page" id="newsDeatils">
            <div data-role="content">
                <h3 id="newsTitle"></h3>
                <p id="newsCategory"></p>
                <div id="newsDescription"></div>   
            </div>
        </div>
    </div>
    </form>
    <script src="<%= ResolveUrl("~/js/jquery.min.js") %>"></script>
    <script>
        $(document).bind("mobileinit", function () {
            $.mobile.autoInitializePage = false;
        });
    </script>
    <script src="<%= ResolveUrl("~/js/jquery.mobile-1.3.0.min.js") %>"></script>    
    <script src="<%= ResolveUrl("~/js/knockout-2.2.0.js") %>"></script>
    <script src="<%= ResolveUrl("~/js/NewsDetails.js" )%>"></script>
    <script>
       $.mobile.initializePage();
    </script>
</body>
</html>

NewsDetails.js 将发送一个 ajax 请求,然后用表格填充 newsDescription div。但是没有任何效果?

【问题讨论】:

    标签: jquery html css jquery-mobile


    【解决方案1】:

    与其延迟初始化整个页面,不如让所有页面都被初始化,然后只初始化新代码。在 jQm v1.3.2 及更早版本中,您可以通过将以下代码添加到成功回调中来做到这一点。

    $('#newsDescription table').trigger('create');
    

    这将允许整个页面初始化并防止在用户网络连接速度较慢时向用户显示无样式页面,这可能导致您的 ajax 请求需要一段时间。

    【讨论】:

      【解决方案2】:

      我已将$.mobile.initializePage(); 放入成功回调中,然后一切正常。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-09-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-04-01
        • 1970-01-01
        相关资源
        最近更新 更多