jQuery Mobile pageinit/pagecreate not firing

后端 未结 7 1918
栀梦
栀梦 2020-12-05 05:24

I have 5 pages - for ease lets say:

  • one.html
  • two.html
  • three.html
  • four.html
  • five.html

When I load each indivi

7条回答
  •  日久生厌
    2020-12-05 06:11

    You require a thourough read of the jQuery Mobile event documentation: http://jquerymobile.com/demos/1.1.0/docs/api/events.html

    The above links gives some great insight into when each of the events fire, here are a couple samples from the page:

    pageinit

    Triggered on the page being initialized, after initialization occurs. We recommend binding to this event instead of DOM ready() because this will work regardless of whether the page is loaded directly or if the content is pulled into another page as part of the Ajax navigation system.

    .

    pageshow

    Triggered on the "toPage" after the transition animation has completed. Callbacks for this event will recieve a data object as their 2nd arg. This data object has the following properties on it: prevPage (object) A jQuery collection object that contains the page DOM element that we just transitioned away from. Note that this collection is empty when the first page is transitioned in during application startup.

    To actually answer your question, don't use pageinit, use pageshow. pageshow fires on the initial showing of a page (just after the pageinit event is fired on the element) but also on subsequent visits to the page.

提交回复
热议问题