gpt4 book ai didi

jQuery Mobile - 返回(硬件)按钮在应用程序中不起作用

转载 作者:行者123 更新时间:2023-12-01 05:02:48 24 4
gpt4 key购买 nike

我是 jQmobile 的新手,一直在关注 jqMobile 网站上的示例。使用多页模板格式,我试图让后退按钮正常工作(硬件按钮)。但是,当我在第二页上按下(硬件)后退按钮时,它只是退出应用程序,而不是返回到第一页。这是我正在使用的示例代码:

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

提前感谢所有回复。

最佳答案

您的设备可能不支持 hashchange 事件。

您可以检查设备与用于更新哈希的 hashchange 事件的兼容性:

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

来源:jQuery - hashchange event

来自 jQuery Mobile 文档:

Hash changes that occur independently of a click, such as when a user clicks the back button, are handled through the hashchange event, which is bound to the window object using Ben Alman's hashchange special event plugin (included in jQuery Mobile). When a hash change occurs (and also when the first page loads), the hashchange event handler will send the location.hash to the $.mobile.changePage() function, which in turn either loads or reveals the referenced page.

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

关于jQuery Mobile - 返回(硬件)按钮在应用程序中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8511087/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com