html5中localStorage的用法(存储在浏览器上)goole测试
bom操作:window.localStorage;
- 判断浏览器是否支持;
if(window.localStorage){
alert('这个浏览器支持本地存储');
}else{
alert('这个浏览器支持不本地存储');
} - 把值存储到localStorage中;
- localStorage.name=”xx”
- localStorage[“name”]=”xx”
- localStorage.setItem(“name”,”xx”)//推荐使用;
- 把localStorage中的值取出来
- 通过浏览器中的Resources–localStorage中可以看到你存储的值。上方有两个–键,值(key,value)name放在key中,”xx”放在va中;
- 取出key值:localStorage.key[i]//(这是错误的);localStorage.key(i);//localStorage.getItem(“c”)//c是key名;
- 取出value值:localStorage.value(i)(这是错误的),localStorage.getItem(localStorage.key(i))