我正在使用 jQuery Mobile 1.1.1 和 Apache Cordova 2.0.0。我希望当按下返回按钮时,我的应用程序退出,但仅在当前页面的 ID = feedZive 时才执行此操作。我正在使用以下代码来实现:
function onDeviceReady(){
document.addEventListener("backbutton", onBackKeyDown, false);
function onBackKeyDown(){
if ($.mobile.activePage.is("#feedZive")){
navigator.app.exitApp();
}
else{
navigator.app.backHistory();
}
}
};
不过看起来我无法获取当前页面,因为我已经尝试过以下代码:
var activePage = $.mobile.activePage;
alert(activePage);
我的警告显示未定义。我也尝试将$.mobile.activePage
更改为$.mobile.activePage.attr("id")
,但它没有起作用。
我的警告显示为未定义。我尝试将$.mobile.activePage
更改为$.mobile.activePage.attr("id")
,但没有生效。
$(document).bind('pageinit', function(e, data){})
中,可以使用e.target.id
。 - Connor Leech