简单的来说localStrage的作用是储存一定的数据在浏览器里面,对于IE浏览器,IE8以上才兼容,首先得判断浏览器是不是支持
if(! window.localStorage){
alert("浏览器不支持localstorage");
return false;
}else{
//主逻辑业务
}
var storage=window.localStorage;
//三种写入数据的方法
//写入a字段
storage["a"]=1;
//写入b字段
storage.b=1;
//写入c字段
storage.setItem("c",3);
//三种读取数据的方法
//第一种方法读取
var a=storage.a;
console.log(a);
//第二种方法读取
var b=storage["b"];
console.log(b);
//第三种方法读取
var c=storage.getItem("c");
console.log(c);
//删除数据的方法
storage.removeItem("a");