jQuery Mobile获取当前页面 [英] jQuery Mobile get current page

查看:763
本文介绍了jQuery Mobile获取当前页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用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();
}

}
};

但是看起来我无法获取当前页面,因为我试过下面的代码: / p>

  var activePage = $ .mobile.activePage; 
alert(activePage);

,我的快讯显示未定义。我也试图将 $。mobile.activePage 更改为 $。mobile.activePage.attr(id)但它不工作。

解决方案

  $(document).live('pagebeforeshow ',function(){
alert($。mobile.activePage.attr('id'));
});

http://jsfiddle.net/ajD6w/5/ p>

I am using jQuery Mobile 1.1.1 and Apache Cordova 2.0.0. I want my app to exit when I press back button but only if current page have ID = feedZive. I am using following code to do it:

function onDeviceReady(){
    document.addEventListener("backbutton", onBackKeyDown, false);
    function onBackKeyDown(){
        if ($.mobile.activePage.is("#feedZive")){
            navigator.app.exitApp();
        }
        else{
            navigator.app.backHistory();
        }

    }
};

However it looks like I can't get the current page because I have tried the following code:

var activePage = $.mobile.activePage;
alert(activePage);

and my alert is showing undefined. I have also tried to change $.mobile.activePage to $.mobile.activePage.attr("id") but it didn't work.

解决方案

$(document).live('pagebeforeshow', function() {
    alert($.mobile.activePage.attr('id'));
});​

http://jsfiddle.net/ajD6w/5/

这篇关于jQuery Mobile获取当前页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆