html5本地存储值

时间:2012-04-06 19:35:55

标签: html5 local-storage

假设我有以下内容存储在localstorage

    var storageObject = {}; 
    storageObject.value = myvalue; 
    storageObject.timestamp = d.getTime(); 
    localStorage.setItem(myref, JSON.stringify(storageObject)); 

如何使用getItem来检索值?

1 个答案:

答案 0 :(得分:0)

简单地:

localStorage.getItem(myref);

甚至:

localStorage[myref];

https://developer.mozilla.org/en/DOM/Storage#localStorage

编辑以从JSON恢复原始对象,只需parse它:

var revivedObject = JSON.parse( localStorage.getItem(myref) ); 
// console.log(revivedObject);