jquery-mobile - jQueryMobile : pagecontainershow on a particular page not working

标签 jquery-mobile

JQueryMobile 1.4 有 deprecated pageshow 事件,而是建议使用 pagecontainershow;但是,虽然我能够在文档级别获取 pagecontainershow 事件,但我无法将函数绑定(bind)到特定页面。

<div id="page1" data-role="page">
...
<script>
  $( "#page1" ).on( "pagecontainershow", function( event, ui ) {
    console.log("page1 pagecontainershow");
  } );
</script>
</div>

演示:http://jsbin.com/IFolanOW/22/edit?html,console,output

我还考虑在我们使用选择器的情况下使用 jQuery“on”函数的替代形式,但这需要是页面 div 的父级,并且可能包括其他页面,所以这不起作用。

作为一种解决方法,我已经这样做了,但是效率非常低:
function registerOnPageShow(pageId, func) {
    var strippedPageId = pageId.replace("#", "");
    var e = "pagecontainershow." + strippedPageId;
    // TODO why isn't it working to use $(pageId) instead of $(document)?
    $( document ).off(e).on(e, null, {page: strippedPageId, f: func}, function(e, ui) {
      if ($(":mobile-pagecontainer").pagecontainer("getActivePage")[0].id == e.data.page) {
        e.data.f(e, ui);
      }
    });
}

最佳答案

您可以像这样获取页面ID。

$(document).on('pagecontainershow', function(e, ui) {
    var pageId = $('body').pagecontainer('getActivePage').prop('id');
});

目前无法在特定页面上显示/隐藏事件。

关于jquery-mobile - jQueryMobile : pagecontainershow on a particular page not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20828948/

相关文章:

ajax - ListView ('refresh' )不工作

html - jquery 移动谷歌地图间歇性显示

html - 在 MVC 和 jQuery Mobile 中基于设备宽度和高度重定向

jquery - 使用 jQuery Mobile 支持的网站使用我自己的主题(样式)设计和图标的正确方法是什么?

jquery - 如何增加jquery mobile select的大小

jquery - 标题的背景图片

javascript - Jquery/JavaScript OnClick 事件未在移动设备上触发

javascript - 从 HTML5 本地存储中检索值

css - JQuery Mobile 从右到左的 css

jquery - 鼠标单击时未启用输入文本