标签:ora copy set 方法 隐私 类型 本质 cookie code
001、localStorage概念
在html5中,新加入了一个localStorage特性,这个特性主要是用来作为本地存储,解决了cookie存储空间不足的问题(cookie中每条cookie存储空间为4K),localStorage支持5M大小。
002、localStorage的局限
003、localStorage的设置
localStorage.name = "凡尘";
localStorage["name"] = "凡尘";
localStorage.setItem("name","凡尘")
004、localStorage的读取
var nameval = localStorage.name;
console.log(nameval);
var nameval = localStorage["name"];
console.log(nameval);
var nameval = localStorage.getItem("name")
005、localStorage的获取
使用key()方法,向其中输入索引即可获取对应的键值
localStorage.a = "1";
localStorage["b"] = "2";
localStorage.setItem("c","3");
for(var i=0;i<localStorage.length;i++){
var key = localStorage.key(i);
console.log(key)
}
006、localStorage的删除
删除所有:
localStorage.clear();
删除某一个值
localStorage.removeItem(key)
localstorage - HTML 5 Web 本地存储总结
标签:ora copy set 方法 隐私 类型 本质 cookie code
原文地址:https://www.cnblogs.com/liuhaov/p/13492581.html