jQuery Mobile | Navigation between Pages

血红的双手。 提交于 2019-11-28 12:59:39

Short answer..

  • Ajax Enabled : No, it is not possible.
  • Ajax Disabled: Yes, it is possible.

Details

Ajax Enabled:

When you use Single Page Model, you have to make sure that you fulfill the below points:

  1. For each HTML, place jQuery, jQM.css and jQM.js in head.
  2. Custom JS should go inside data-role=page div.
  3. Each data-role=page div in a separate HTML file.

Note: jQM loads ONLY first data-role=page div of each HTML file into DOM. Anything outside data-role=page div is neglected. That's why Custom JS should be placed inside that div.

When you navigate away from a page (except very first page loaded) jQuery Mobile removes that page from DOM. Unless you cache it by adding data-dom-cache="true" to data-role=page div. The page is removed from DOM, however, CSS and JS are cached. To remove them, you need to refresh/reload the page completely.

Hence, when you navigate from pageX.html to pageY.html via Ajax, if you override CSS in pageZ, they will be applied on pageX (in case you used same selectors).

To safely override CSS of different pages, create custom classes and addClass() / removeClass() depending on page. Or, use #pageID selector to be more specific when you override CSS. The same applies for JS, you should be specific when you use Page Events.

Ajax Disabled:

You can do whatever you want, the website will be using HTTP not Ajax.

Demo

Not sure you can restore the previous state with several html files.

You should use the multi-page template of JQM and set all your html in one file with each page in a div with the data-role="page" and a specific id :

<div data-role="page" id="foo">
</div>
<div data-role="page" id="bar">
</div>

With that, you will be able to keep the state of each pages.

The JQM documentation : http://demos.jquerymobile.com/1.4.2/pages/#Multi-pagetemplatestructure

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