localStorage和sessionStorage的方法
setItem存储value
用途:将value存储到key字段
用法:.setItem( key, value)
代码示例:
localStorage.setItem("key","value");
sessionStorage.setItem("key","value");
getItem获取value
用途:获取指定key本地存储的值
用法:.getItem(key)
代码示例:
localStorage.getItem("key");
sessionStorage.getItem("key");
removeItem删除key
用法:.clear()
代码示例:
localStorage.clear();
sessionStorage.clear();
storage属性遍历length;
var storage = localStorage.length;
for(var i =0 ; i< storage; i++){
console.log(storage.key(i)+":"+storage.getItem(storage.key(i))+"<br/>");
}