使用html5中的localstorage来存储动态创建的div而不使用数据库

时间:2013-04-23 15:48:47

标签: android html5 cordova mobile local-storage

我正在尝试使用Html5 css3 jquery,jquery mobile phonegap和Dreamweaver cs6开发一个Web应用程序(混合应用程序)。

在我的应用程序中,我有三个选择框,有不同的选项和一个按钮。当用户在选择所有三个选择框的选项后单击按钮时,将创建一个div。直到这里它很好,但一旦应用程序刷新或移动到另一页,我来失去创建的div。这个程序是一个演示应用程序,所以我没有使用任何数据库。有没有办法我可以使用本地存储来保存这个div,以便我可以在我回到应用程序时检索。

1 个答案:

答案 0 :(得分:3)

当然可以

保存

if (('localStorage' in window) && window['localStorage'] !== null) {
        var divtosave = $("#divtosave").html();
        localStorage.setItem('saveddiv', divtosave);
});

使用它

if ('saveddiv' in localStorage) {
        $("#div").html(localStorage.getItem('saveddiv'));
}

清除

localStorage.clear(); //release it