JSON對(duì)象存儲(chǔ)
JSON對(duì)象提供的parse和stringify將其他數(shù)據(jù)類型轉(zhuǎn)化成字符串,再存儲(chǔ)到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();
作者:調(diào)皮的小喵喵喵
鏈接:http://www.itdecent.cn/p/c2da79069d5c
來(lái)源:簡(jiǎn)書(shū)
著作權(quán)歸作者所有。商業(yè)轉(zhuǎn)載請(qǐng)聯(lián)系作者獲得授權(quán),非商業(yè)轉(zhuǎn)載請(qǐng)注明出處。