1、判断浏览器是否支持 localStorage 属性
if (window.localStorage) { alert('This browser supports localStorage');} else { alert('This browser does NOT support');}
2、localStorage 的存储格式都是字符串,任何其他类型都会转成字符串存储。
3、存值
localstroage.setItem('uid','10001');
4、取值
var uid = localstroage.getItem('uid');
5、删除某个值
localstroage.removeItem('uid');
6、删除所有值
localstroage.clear();
7、遍历所有键值
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 )) );}
8、jQuery操作Cookies
【文章链接:https://www.cnblogs.com/yonge/articles/2698106.html】