tbl*_*y89 9 jquery jquery-mobile
我基本上只需要一个自定义函数,例如,当从主页点击#reviews页面时.
这是我正在使用的当前代码:
$(document).bind("mobileinit", function(){
$('#reviews').live('pagebeforeshow',function(event){
var cpage = $.mobile.activePage.attr('id');
if (cpage == 'home') {
addPages();
}
});
});
Run Code Online (Sandbox Code Playgroud)
问题是,即使它正在使用'pagebeforeshow',它正在使用它将要转换为活动页面的页面的id,在这种情况下是'reviews'而不是home,从而导致if语句失败.
所以我的问题是,在这个例子中,我将如何获得上一页的id,以确保它实际上来自#home页面?
Mic*_*ouw 22
要完成答案:您将获得一个jQuery对象,因此要获取页面的ID,请执行以下操作:
$("#page-id").live('pagebeforeshow', function(event, data) {
console.log("the previous page was: " + data.prevPage.attr('id'));
});
Run Code Online (Sandbox Code Playgroud)
data.prevPage将上一页作为jQuery对象,
.attr('id')从该jQuery对象获取id.
pagebeforeshow
事件处理程序实际上得到2个参数:event和ui.您可以从ui访问上一页.这是来自jquery-mobile事件文档的示例:
$('div').live('pageshow', function(event, ui){
alert( 'This page was just hidden: '+ ui.prevPage);
});
Run Code Online (Sandbox Code Playgroud)
所有4页显示/隐藏事件的参数都是相同的.
归档时间: |
|
查看次数: |
16452 次 |
最近记录: |