gpt4 book ai didi

jquery - 如何检测Android上的后退和菜单按钮? PhoneGap + jQuery 移动

转载 作者:行者123 更新时间:2023-12-01 00:07:12 26 4
gpt4 key购买 nike

我使用的是 jQuery Mobile v1.2.0 和 PhoneGap v2.2.0。无论我怎么调用它,似乎都没有触发任何 PhoneGap 事件(无论是通过 document.addEventListener 还是 $(document).on 。后退按钮和菜单按钮检测不起作用。

还有其他类似的问题,但到目前为止我所能看到的只是使用 document.addEventListener 的建议或者使用 jQuery 方法来添加事件监听器,但它确实不起作用。有人能给我一个可靠的方法来检测它们吗?

这是 <head>我的index.html

<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="format-detection" content="telephone=no" />
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />

<link rel="stylesheet" href="jqm/jquery.mobile-1.2.0.css" />
<link rel="stylesheet" href="jqm/jquery.mobile.theme-1.2.0.css" />
<script src="js/jquery.js"></script>
<script src="jqm/jquery.mobile-1.2.0.js"></script>
<script src="js/cordova.js"></script>
<script type="text/javascript">
$(document).live("pagechange",function(){
var page = $.mobile.activePage.attr("id");

document.addEventListener("menubutton", menuKeyDown, true);
function menuKeyDown() {
alert('Menu button pressed.');
}
});
</script>
</head>

最佳答案

在上传到 build.phonegap.com 之前删除项目中的“cordova.js”。并尝试下面的代码。

<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="format-detection" content="telephone=no"/>
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi"/>
<link rel="stylesheet" href="jqm/jquery.mobile-1.2.0.css"/>
<link rel="stylesheet" href="jqm/jquery.mobile.theme-1.2.0.css"/>
<script src="js/jquery.js"></script>
<script src="jqm/jquery.mobile-1.2.0.js"></script>
<script src="js/cordova.js"></script>
<script type="text/javascript">
$(document).live("pagechange",function(){
var page = $.mobile.activePage.attr("id");
});
document.addEventListener("deviceready", function () {
document.addEventListener("menubutton", menuKeyDown, true);
}, false);
function menuKeyDown() {
alert('Menu button pressed.');
}
</script>
</head>

关于jquery - 如何检测Android上的后退和菜单按钮? PhoneGap + jQuery 移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14032214/

26 4 0