2011-12-14 23 views
2

我是jQmobile的新手,並且一直關注jqMobile網站上的示例。使用多頁面模板格式,我試圖讓後退按鈕工作(硬件按鈕)。但是,當我在第二頁上時,按(硬件)返回按鈕,它只是退出應用程序,而不是返回到第一頁。下面是我使用的示例代碼:jQuery Mobile - 返回(硬件)按鈕在應用程序中不起作用

<head> 
<title>PhoneGap</title> 
<script type="text/javascript" charset="utf-8" src="phonegap-1.2.0.js"></script> 
<meta name="viewport" content="width=device-width,height=device-height,initial-scale=1"> 

<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css" /> 
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script> 

<script type="text/javascript"> 
//This is your app's init method. Here's an example of how to use it 
function init() { 

    document.addEventListener("deviceready", onDR, false); 

} 

function onDR(){ 
    //document.addEventListener("backbutton", backKeyDown, true); 
    navigator.notification.alert("PhoneGap is working"); 
    //boot your app... 

} 

function backKeyDown() { 

    // do something here if you wish  
} 



$(document).bind("mobileinit", function(){ 
    $.mobile.touchOverflowEnabled = true; 
    $.mobile.defaultPageTransition = 'fade'; 
}); 



</script> 
<script type="text/javascript" src="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js"></script> 
</head> 

<!-- Start of first page --> 
<div data-role="page" id="foo"> 

    <div data-role="header"> 
     <h1>Foo</h1> 
    </div><!-- /header --> 

    <div data-role="content"> 
     <p>I'm first in the source order so I'm shown as the page.</p>  
     <p>View internal page called <a href="#bar">bar</a></p> 
    </div><!-- /content --> 

    <div data-role="footer"> 
     <h4>Page Footer</h4> 
    </div><!-- /footer --> 
</div><!-- /page --> 


<!-- Start of second page --> 
<div data-role="page" id="bar"> 

    <div data-role="header"> 
     <h1>Bar</h1> 
    </div><!-- /header --> 

    <div data-role="content"> 
     <p>I'm the second in the source order so I'm hidden when the page loads. I'm just shown if a link that references my ID is beeing clicked.</p>  
     <p><a href="#foo">Back to foo</a></p> 
    </div><!-- /content --> 

    <div data-role="footer"> 
     <h4>Page Footer</h4> 
    </div><!-- /footer --> 
</div><!-- /page --> 
</body> 

感謝,提前對所有的答覆。

+0

我不認爲這是有可能改變智能手機的硬件按鈕的行爲,特別是與JavaScript ..和BTW ..哪裏是你的JavaScript?你只發布標記... – MilkyWayJoe 2011-12-14 20:25:42

+1

你在用什麼設備 ? – 2011-12-14 21:36:56

回答

1

有可能您的設備不支持hashchange事件。

您可以檢查與被用於更新哈希hashchange事件設備的兼容性:

if ("onhashchange" in window) { 
    //... 
} 

來源:jQuery - hashchange event

從jQuery Mobile的文檔:

獨立於點擊發生的哈希變化,例如當用戶點擊了 後退按鈕,通過使用Ben Alman的hashchange 特殊事件插件(包含在jQuery Mobile中)綁定到窗口對象的hashchange事件 進行處理。當發生散列更改 (以及第一頁加載時),hashchange事件 處理程序將發送location.hash到$ .mobile.changePage() 函數,該函數反過來加載或顯示引用的頁面。

來源:http://jquerymobile.com/test/docs/pages/page-navmodel.html

相關問題