Jquery mobile jQuery mobile 1.4中的pageshow与pagecontainershow

Jquery mobile jQuery mobile 1.4中的pageshow与pagecontainershow,jquery-mobile,Jquery Mobile,我正在将jQuery移动站点更新为1.4.2 当我更改此选项时: $(document).delegate('#locations', 'pageshow', LocationsPageShown); 为此: $('#locations').on('pagecontainershow', LocationsPageShown); 它不再触发事件。FWIW,这将触发事件: $(document).on('pagecontainershow', LocationsPageShown); 当然,

我正在将jQuery移动站点更新为1.4.2

当我更改此选项时:

$(document).delegate('#locations', 'pageshow', LocationsPageShown);
为此:

$('#locations').on('pagecontainershow', LocationsPageShown);
它不再触发事件。FWIW,这将触发事件:

$(document).on('pagecontainershow', LocationsPageShown);
当然,我需要在显示位置页面时启动它,而不仅仅是一个通用的文档选择器

---编辑1---

这项工作:

$(document).on('pageshow', '#locations', LocationsPageShown);
但这并不是:

$('body')。在('pagecontainershow','LocationsPageShown')


pagecontainershow的选择器应为:mobile pagecontainer。如果这不适用于您,您可以使用$(“body”),如1.4所示,body始终是页面容器:

$(":mobile-pagecontainer" ).on( "pagecontainershow", function( event, ui ) {
  alert( "This page was just hidden: " + ui.prevPage );
  alert( "The current page is : $(":mobile-pagecontainer" ).pagecontainer( "getActivePage" ));
});
事件的第二个参数(上面示例中的ui)提供您来自的页面。要获取当前页面,可以使用
$(“:mobile pagecontainer”).pagecontainer(“getActivePage”)

因此,您可以查看当前页面ID来决定应该运行哪些代码。

如中所述:

在jQuery Mobile 1.4.0中,这两个事件除了名称和pagecontainershow在pagecontainer上触发,而pageshow在pagecontainer上触发之外是相同的

因此,主要区别在于页面容器接收
pagecontainershow
,而
pageshow
直接从页面接收。从
pagecontainershow
可以将目标页面作为
ui.toPage
获取,其
id
ui.toPage[0]。id

$(document).on("pagecontainershow", function(e, ui) {
    // Refer page as ui.toPage or ui.toPage[0].id
    ...
});   

哦,可能是因为我使用$.mobile.changePage(“#locations”);而不是$.mobile.pageContainer.pageContainer('change','#locations');不,我不认为是这样的…新的页面容器不能被授权如何利用pageContainer事件只使用$(document)。on('pagecontainershow',function(event,ui){…}