2013-05-29 41 views
0

我有一個簡單的jQuery Mobile應用程序,本質上是2頁。當我導航到jQuery Mobile中的頁面時,Javascript函數未被調用

第一頁有一個按鈕:

<a href="location.html" data-theme="b" data-role="button" data-icon="arrow-r">Create Report</a> 

當按鈕我瀏覽到location.html點擊,這個頁面都有自己的JS文件,該文件裏面如下:

(function($, undefined) { 
    $(document).on("pageshow", function(){ 
     initMap(); 
    }); 
})(jQuery); 

但是,當我到達頁面時,JS函數initMap();未被調用,如果我刷新頁面,該函數將被調用,但在我使用主頁上的按鈕進行導航時不會被調用。

如何確保在每次導航到此頁面時調用此函數?

回答

1

我希望你有你的location.html頁的ID嘗試。東西如下

<div data-role="page" id="location"> 
</div> 

改變你的js文件的內容如下

$(document).on('pageshow', '#location', function(){ 
    initMap(); 
}); 

現在這應該每次訪問頁面時調用該函數。

相關問題