您现在的位置是:首页 > 杂谈 > js的本地存储事件localstorage 网站首页 杂谈

js的本地存储事件localstorage

Tom2018-06-14 4903人围观
杂谈  
简介 暂无

localstorage的特点:本地不过期,除非主动清空

使用方法:

设置localstorage:

localStorage.setItem(name, JSON.stringify(val))

获得localstorage:

localStorage.getItem(name)

清空localstorage:

localStorage.removeItem(name)

注意事项:

localstorage中只能存字符串类型,一般使用都是存入json的字符串,这里提示两个函数

js的数组转json:

JSON.stringify( arr );

js的json转数组:

JSON.parse( jsonStr );

当然还有很多本地js存储的方法和事件,暂时只收集了一种,以后持续更新


-本章-end--

打赏本站,你说多少就多少

文章评论

image
2018-06-14 你※※
这种高级东西 666啊
image
2019-11-24 win用户
我觉挺好用的
image
2021-02-20 231
123