【问题标题】:Data persists in mutli page layout in jquery mobile数据在 jquery mobile 中保留在多页面布局中
【发布时间】:2015-02-13 09:03:59
【问题描述】:

有没有办法在多页面布局中用data-role="page"刷新特定的div。我已经走了通过此链接Does jQuery's .data() cache persist across page transitions in jQuery mobile? 但没有刷新 div 的解决方案。我没有从任何服务器加载任何 html 内容。当我使用 reload:true 时,整个应用程序重新加载(是因为,我在页面之间导航时使用 changeHash:false)。提前致谢。

$("#buttonID").click(function(){     
    $.mobile.changePage("#PageId",{
        allowSamePageTransition: true,
        transition: 'fade', 
        changeHash: false
    });
});

【问题讨论】:

    标签: javascript jquery jquery-mobile


    【解决方案1】:

    HTML

     <div data-role="page" id="page1">
        <div data-role="header" class="">
            <h3>Home</h3> 
        </div>
        <div role="main" id="mycontent" class="ui-content">
            "Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit...""There is no one who loves pain itself, who seeks after it and wants to have it, simply because it is pain..."
            <a href="" data-role="none" class="ui-btn" id="btn-refresh"> Refresh    </a>
        </div>
     </div>
    

    JAVASCRIPT

    $(document).on("click", "#btn-refresh", function () {
        $("#mycontent").empty();
        $("#mycontent").html("Lorem Ipsum is simply dummy text of the printing and typesetting industry.");
        $("div[data-role=page]").trigger("create");
        $.mobile.changePage("#product_page", {
           allowSamePageTransition: true,
           transition: 'flip',
           changeHash: false
        });
    })
    

    Demo

    【讨论】:

    • 我有一个接收图像的表单,几个文本字段和一个需要发送到服务器的复选框。每当我第二次导航到表单时,数据(先前选择的图像和文本字段的值)仍然存在。
    • 是的,您可以进行简单的 ajax 调用。从服务器获得成功回调后,您可以更改页面。
    猜你喜欢
    • 1970-01-01
    • 2011-09-17
    • 1970-01-01
    • 1970-01-01
    • 2014-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多