jQuery Mobile popup is not opening on .popup('open')

隐身守侯 提交于 2019-12-03 15:12:02

That's because when pageinit is fired, the poupup isnt ready for manipulation just yet. You need to use pageshow to get the popup to open. Here's what you do :

  • Make the ajax call in pageinit. store the data in data attribute of the page.
  • Then, in the pageshow event, take if from data and manipulate it the way you want, then open the popup.

Here's the code :

$(document).on({
    "pageinit": function () {
        alert("pageinit");
        //$("#popupBasic").popup('open'); will throw error here because the page is not ready yet
        //simulate ajax call here
        //data recieved from ajax - might be an array, anything
        var a = Math.random();
        //use this to transfer data betwene events
        $(this).data("fromAjax", a);
    },
    //open popup here
    "pageshow": function () {
        alert("pageshow");
        //using stored data in popup
        $("#popupBasic p").html("Random : " + $(this).data("fromAjax"));
        //open popup
        $("#popupBasic").popup('open');
    }
}, "#page1");

And here's a demo : http://jsfiddle.net/hungerpain/MvwBU/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!