检测多个页面的 pageshow(n)
Posted
技术标签:
【中文标题】检测多个页面的 pageshow(n)【英文标题】:detect pageshow(n) for multiple pages 【发布时间】:2014-05-17 02:00:19 【问题描述】:我已经创建了一个处理程序来捕获多个年龄段的页面显示,就像这样
$(document).on('pageshow',"#novels, #book, #toys",function(event)
每个页面都有这样的 id
<div data-role="page" data-theme="c" id="pagename"></div>
如何获取调用 pageshow 事件的页面,我试过了
console.log($(this).attr('id'));
在页面显示事件中,但在控制台中得到undefined
【问题讨论】:
你试过$(event.target).attr('id')
吗?
【参考方案1】:
jQuery 移动
$(document).on("pageshow", function ()
var activePage = $.mobile.activePage[0].id;
console.log( activePage ); // pageID of active page
);
jQuery 移动 >= 1.4
$(document).on("pagecontainershow", function ()
var activePage = $.mobile.pageContainer.pagecontainer("getActivePage")[0].id;
console.log( activePage ); // pageID of active page
);
$(document).on("pageshow", function ()
var activePage = $.mobile.activePage[0].id;
console.log( activePage ); // pageID of active page
);
$(document).on("pagecontainershow", function ()
var activePage = $.mobile.pageContainer.pagecontainer("getActivePage")[0].id;
console.log( activePage ); // pageID of active page
);
【讨论】:
以上是关于检测多个页面的 pageshow(n)的主要内容,如果未能解决你的问题,请参考以下文章
Jquery Mobile:“pageshow”事件仅在 Shift F5(完全重新加载)时触发,但在加载另一个页面或具有不同查询的同一页面时不会触发
jQuery Mobile - pageinit 与 pageshow
Ionic2 - 根据检测到的设备名称,将全局类添加到整个应用程序页面