Jquery移动活动页面

Jquery mobile active page

本文关键字:活动页 移动 Jquery      更新时间:2023-09-26

web开发新手报告:

我正在使用jquery编写我的第一个移动应用程序,目前卡在那里:

对于一些额外的功能,我想得到当前活动页面的url。我发现这可以用$.mobile来完成。activePage。例如,下面的代码按我的预期工作:

$(document).on("pagecreate",function(){
    console.log($.mobile.activePage[0].baseURI);
}); 

然而,当我按"后退"按钮,Uncaught TypeError: Cannot read property 'activePage' of undefined出现在控制台和应用程序挂起。

问题:我该如何处理这种情况?谢谢!

你应该做的有点不同,使用以下代码:

$(document).on("pageshow",'.ui-page',function(){
    console.log($.mobile.activePage[0].baseURI);
}); 

工作示例:http://jsfiddle.net/Gajotres/vds2U/82/