JSON对象存储
JSON对象提供的parse和stringify将其他数据类型转化成字符串,再存储到storage中就可以了
操作的方式:
存:
var obj = {"name":"ergouzi","age":"16"}
localStorage.setItem("userInfo",JSON.stringify(obj));
取:
var user = JSON.parse(localStorage.getItem("userInfo"))
删除:
localStorage.removeItem("userInfo);
清空:
localStorage.clear();