sessionStorage.setItem('xxx',true), get the result "true" string
sessionStorage.setItem('xxx',{}), get the result "[object Object]"
How Save other types?
迷茫2017-05-18 10:55:07
sessionStorage
和localStorage
只能存字符串,针对对象需要存储storage
If you want, you can serialize it to achieve the effect:
var obj = {};
sessionStorage.setItem('xxx', JSON.stringify(obj)); //序列化
obj = JSON.parse(sessionStorage.setItem('xxx')); //这时候需要反序列化一下
Reference:
localStorage stores JSON objects
JS operation JSON
世界只因有你2017-05-18 10:55:07
webStorage itself can store non-strings, but no browser has implemented it yet