首页 > 代码库 > Web 存储之localStorage

Web 存储之localStorage

 1、localStorage的浏览器支持情况

  localStorage属于永久性存储,不移除永久存在;sessionStorage属于会话结束就消失。

  localStorage存储的大小在5M左右,不同浏览器有所区别。

技术分享

 

2、localStorage存储

localStorage.setItem(key, value);

3、localStorage读取

localStorage.getItem(key)

4、localStorage移除

localStorage.removeItem(k);

5、localStorage循环

for (var i = 0; i < localStorage.length; i++) {      var k = localStorage.key(i);      var v = localStorage.getItem(k);}

 

Web 存储之localStorage