数据在jquery mobile中的多页面布局中仍然存在

时间:2015-02-13 09:04:00

标签: javascript jquery jquery-mobile

是否有办法在多页面布局中使用 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
    });
});

1 个答案:

答案 0 :(得分:0)

<强> 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