localStorage的详细用法

韩佳*

localStorage

项目描述

localStorage的详细用法

上传时间

2021.06.25

浏览人数

917人
韩佳*
天津市南开区
Hot:20129

关于localStorage:

1. localStorage会可以将第一次请求的数据直接存储到本地,这个相当于一个5M大小的针对于前端页面的数据库,但是这个却是只有在IE8以上的IE版本的浏览器才支持.

2. 目前所有的浏览器中都会把localStorage的值类型限定为string类型,使用时需要将JSON对象类型做转换.

3. localStorage在浏览器的隐私模式下面是不可读取的.

4. localStorage不能被爬虫抓取到.

localStorage与sessionStorage的唯一一点区别就是localStorage属于永久性存储,而sessionStorage属于当会话结束的时候,sessionStorage中的键值对会被清空.

用法:

1. 保存:

let i = {
   name: "乌龙奶茶",
   des: "去冰三分糖加珍波椰"
};
//使用localStorage就需转化string类型
i = JSON.stringify(i);
console.log(i);
localStorage.setItem("MilkTea", i);
//或者直接
localStorage.setItem("Cake", "豆乳盒子");
localStorage.setItem("HotPot", "一片毛肚");

localStorage的详细用法

2. 获取

let x = localStorage.getItem("MilkTea");
console.log(x);
x = JSON.parse(x);
console.log(x.name);

localStorage的详细用法

3. 移除某一项

localStorage.removeItem("CAKE");

4. 全部清空

localStorage.clear()

5. 返回存储对象第n个数据项的键名

let x = localStorage.key(0);
console.log(x);
let y = localStorage.key(2);
console.log(y);

localStorage的详细用法localStorage的详细用法


6. localStorage存储变量的个数

let len = localStorage.length;
console.log(len);

localStorage的详细用法

7. 检查localStorage上是否保存了某变量

let x = localStorage.hasOwnProperty("HotPot");
console.log(x);
let y = localStorage.hasOwnProperty("Candy");
console.log(y)

localStorage的详细用法

韩佳*

当前作品暂无评分

还未获得评语哦~
python python培训 天津python培训 python培训班 python培训多少钱 Django 天津python培训班 天津python培训 天津python培训机构。天津python培训学什么? python python培训 天津python培训 Mysql django Numpy flask anaconda 天津python培训 天津python培训班 python培训 python 天津python培训 天津python培训班 数据爬虫 爬虫技术 python爬虫 python 天津python培训 python培训 python PyCharm Eclipse + 天津python培训 python培训 python PyCharm Eclipse + PyDev python培训 天津python培训 python培训班 python培训多少钱 PyCharm Eclipse + PyDev visual studio 天津python培训 天津python培训班 PyCharm Eclipse + PyDev visual studio 天津python培训 天津python培训班 天津python培训机构 python培训班 C/C++ Java Python 天津python培训 天津python培训班 天津python培训机构 python培训班 C/C++ Java Python 天津python培训 天津python培训班 天津python培训机构 python培训班 C/C++ Java Python 天津python培训 天津python培训班 天津python培训机构 python培训班 C/C++ Java Python 天津python培训 天津python培训班 天津python培训机构 python培训班 python java web 天津python培训 天津python培训哪家好 天津python培训机构 天津python培训班 python java web前端 天津python培训 天津python培训班 天津python培训机构 天津python培训学校 python java web 天津python培训 天津python培训班 天津python培训机构 python培训 python java web 天津python培训 天津python培训班 天津python培训机构 天津python培训学校 python java web 天津python培训 天津python培训班 天津python培训机构 python java web 天津python培训 天津python培训班 天津python培训机构 天津python培训学校 python Java web 天津python培训 天津python培训学校 天津python培训机构 天津python培训班 python java web 天津python培训 天津python培训班 天津python培训机构 python培训 python Java web 天津python培训 天津python培训机构 天津python培训班 python培训 python java web 天津python培训 天津python培训机构 天津python培训学校 python培训 python java web 天津python培训 天津python培训班 天津python培训机构 python培训 python java web 天津python培训 天津python培训班 天津python培训机构 python培训 python java web 天津python培训 天津python培训班 天津python培训机构 python培训学校 python java web 天津python培训 天津python培训机构 python培训班 python java web 天津Java培训 天津Java培训班 Java培训 天津Java培训机构 python web java 天津python培训 天津python培训班 天津python培训机构 python java web 天津python培训 天津python培训班 python培训 天津python培训机构 python java web 天津python培训 天津python培训班 天津python培训机构 python培训 python web java 天津python培训 天津python培训班 python培训 python web java 天津python培训 天津python培训班 python培训 python web java 天津python培训 天津python培训机构 天津python培训学校 python web java 天津python培训班 天津python培训机构 天津python培训学校 python java web 天津python培训 天津python培训机构 python培训 python web java 天津python培训 天津python培训班 python培训 python web java 天津python培训 天津python培训机构 python培训 python web java 天津python培训 天津python培训班 python培训 python web java 天津python培训 天津python培训班
韩佳*    20129 天津市南开区 设计师杨冰是女孩 1997.**.**
本网站已在中国版权保护中心登记了美术作品著作权与软件著作权违者将依法追究责任,特此声明! | Copyright©2013-2022,zhuzuoji.com | 诚筑说培训学校(天津)有限公司内容支持 | 京ICP备17020986号-5