我的应用程序有两个面板作为主布局,所以所有的子页面都有这两个面板。现在,我想为应用程序中的所有页面注册滑动事件,以便用户可以从任何地方访问这两个面板。 我创造了这个功能,在这里,这样我就可以把这种来自不同的地方进行注册:如何在JQM应用程序的所有页面上注册刷卡事件?
function registerSwipeEvents() {
//panel swipe from left and right for categories, favs.
$(document).on("swipeleft swiperight", '[data-role=page]', function (e) {
// We check if there is no open panel on the page because otherwise
// a swipe to close the left panel would also open the right panel.
// We do this by checking the data that the framework stores on the page element (panel: open).
if ($.mobile.activePage.jqmData("panel") !== "open") {
if (e.type === "swipeleft") {
$(".right-panel").panel("open");
} else if (e.type === "swiperight") {
$(".left-panel").panel("open");
}
}
});
}
我已经打过电话,从pageinit此功能(运行脚本只有一次),pagebeforeshow和pageshow(始终运行),如这个:
$('#HomePage').on('pageshow', function() {
getFavouritesFromClient();
});
但是这个事件不适用于所有页面,当我第二次从一个页面转到另一个页面时!也许我没有正确地使用这些事件,但是迄今为止第一轮导航工作的最好的一个是pageshow。
你使用的是单文件还是多文件? – Omar
@Omar多个文件,但主页ID是我的主'[data-role = page]'的主要ID,并且所有进入的内容都被注入到内容中。 –
'$(document).on('pageshow','#HomePage',function(){'将会诀窍。另外,通过这个答案,这很有帮助http://stackoverflow.com/a/15806954/1771795 – Omar