localStorage - 没有时间限制的数据存储
1 var arr=[1,2,3];
2 localStorage.setItem("temp",arr); //会返回1,2,3
3 console.log...(typeof localStorage.getItem("temp"));//string
4 console.log(localStorage.getItem("temp"));//1,2,3
localStorage.setItem...3 localStorage.setItem("temp2", obj);//但是返回[object Object]
用localStorage.setItem()正确存储JSON对象方法是:
存储前先用...("temp2", obj);//返回{"a":1,"b":2}
后续要操作该JSON对象,要将之前存储的JSON字符串先转成JSON对象再进行操作
1 obj=JSON.parse(localStorage.getItem...*/
14
15 PersonInfo.prototype.saveToLocalStorage = function () {
16 // 将 this 写入 本地存储