2015-12-01 250 views
0

我正在使用下面的代碼刷新頁面。但是,在將button移動到header時,它不再適用。所以button需要在content部分才能工作。我猜它是與.mobile.changePage刷新頁面按鈕點擊jquery mobile

function refreshPage() { 
$.mobile.changePage(
window.location.href, 
{ 
    allowSamePageTransition : true, 
    transition    : 'none', 
    showLoadMsg    : false, 
    reloadPage    : true 
} 
); 
} 

$(window).load(function(){ 
$('#refresh').on('click', function (e) { 
    refreshPage(); 
}); 
}) 

我使用下面的代碼調用按鈕:

<div data-role="header"> 
    <button id="refresh" data-icon="refresh">Refresh</button> 
</div> 
+0

你所有的頁面都在一個html文件中(很多data-role =「page」divs,或者你是鏈接到多個html文件嗎? – ezanker

+0

這只是一個文件 – Andreas

回答

1

可以使用pagecontainer部件得到active page,然後用它刷新所述change方法:

function refreshPage() { 
    var curPageID = $(":mobile-pagecontainer").pagecontainer("getActivePage").prop("id"); 
    $(":mobile-pagecontainer").pagecontainer("change", "#" + curPageID, { 
    allowSamePageTransition : true, 
    }); 
} 

也代替$(窗口).load(函數(){...使用JQM pagecreate事件

$(document).on("pagecreate","#page2", function(){ 
    $('#refresh').on('click', function (e) { 
     refreshPage(); 
    }); 
}); 

DEMO

在演示中,導航到第2頁和然後點擊刷新。

+0

這對我有效;刷新足夠深以執行ajax調用和其他javascript更新(就像Ctr + F5一樣)。關於如何進行「深度」刷新的任何想法?非常感謝。 –

+0

@CarlosGarcia您必須發佈您的代碼,它可能取決於你使用哪個頁面事件... – ezanker