jQuery Mobile:获取上一页的ID [英] jQuery Mobile: Getting ID of previous page

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

问题描述

我基本上需要一个自定义函数,仅在例如从主页上单击#reviews页面时使用.

I basically need a custom function to be used only when, for example, the #reviews page is clicked on from the home page.

这是我正在使用的当前代码:

Here is the current code I am using:

$(document).bind("mobileinit", function(){
    $('#reviews').live('pagebeforeshow',function(event){
    var cpage = $.mobile.activePage.attr('id');
        if (cpage == 'home') {
            addPages();
        }
    });
});

问题是,即使它使用的是"pagebeforeshow",它使用的是将要转换为活动页面的页面的ID,在这种情况下,它是"views"而不是home,从而导致if语句失败.

The problem is, even though it is using 'pagebeforeshow' it is using the id of the page it is about to transition to as the active page, in this case 'reviews' rather than home, thus causing the if statement to fail.

因此,在这个示例中,我的问题是,如何获取上一页的ID,以确保它实际上来自#home页面?

So my question is, in this example, how would i get the id of the previous page, to make sure it is in fact coming from the #home page?

推荐答案

要完成答案:您将获得一个jQuery对象,因此要获取页面的ID,请执行以下操作:

To complete the answer: you will get a jQuery object back, so to get the ID of the page do this:

$("#page-id").live('pagebeforeshow', function(event, data) {
    console.log("the previous page was: " + data.prevPage.attr('id'));
});

data.prevPage 正在将上一页作为jQuery对象,

data.prevPage is getting the previous page as jQuery object,

.attr('id')正在从该jQuery对象获取ID.

.attr('id') is getting the id from that jQuery object.

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

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