假设我有以下内容存储在localstorage
中 var storageObject = {};
storageObject.value = myvalue;
storageObject.timestamp = d.getTime();
localStorage.setItem(myref, JSON.stringify(storageObject));
如何使用getItem来检索值?
答案 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);