jQuery Mobile页面返回无需重新get

来源:互联网 发布:风险矩阵图怎么画 编辑:程序博客网 时间:2024/06/03 03:58

最近公司的web app项目,使得我有幸一直接触和学习jQuery Mobile。这确实是一个很不错的移动开发库,有助于擅长web开发的工程师,快速入门并构建自己的移动应用。但是在前两天,我碰到了一个问题,使我查了很多资料都没有找到很好的解决方案,最终只能逼着我读jQuery Mobile的源码,再写了个扩展,才得以解决。下面请让我娓娓道来。

问题描述

假设在项目中,有三个页面,分别是main.html、test1.html、test2.html(后面分别简称main、test1、test2),其中main页面是包含一个转向到test1页面的链接(即a标签),test1中有一个属性为data-rel=”back”的链接和一个转向到test2的链接,test2只有一个属性为data-rel=”back”的链接。。这样导致的问题就是:

原因分析

解决问题

经过一番查找,在jQuery Mobile官网看到一段《Caching pages in the DOM》的描述:

Caching pages in the DOM

To keep all previously-visited pages in the DOM, set the domCache option on the page plugin to true, like this:

$.mobile.page.prototype.options.domCache = true;


Alternatively, to cache just a particular page, you can add the data-dom-cache="true" attribute to the page's container:

<div data-role="page" id="cacheMe" data-dom-cache="true">


You can also cache a page programmatically like this:

pageContainerElement.page({ domCache: true });


The drawback of DOM caching is that. If you enable DOM caching, take care to manage the DOM yourself and test thoroughly on a range of device…………………………………………………………………………

文献:http://www.verydemo.com/demo_c110_i33106.html

0 0
原创粉丝点击