localstorage的使用
1.获取对象
var localstroage = window.localStorage;
2.存储值
localstroage.setItem('openid','ksjhfkjajkdfjkszdjfksad'); localstroage.setItem('uid','10001');
3.获取值
var openid = localstroage.getItem('openid');
4.删除某个值
localstroage.removeItem('openid');
5.删除全部值
localstroage.clear();
6.遍历全部键值
localStorage.uid = 1;localStorage.sex='nan';localStorage.age = 23;for ( var i = 0, len = localStorage.length; i < len; ++i ) { console.log( localStorage.key( i ) +':' + localStorage.getItem(localStorage.key( i )) );}注意:1. 假设不主动删除 localstorage 是不会自己主动清空的 不会像cookie一样清除
2. localstorage 差点儿支持大部分浏览器 不用考虑IE8 的问题 大小为 5M