当前位置:网站首页>JS local storage
JS local storage
2022-06-13 09:41:00 【A-L-Kun】
List of articles
The local store
One 、 An introduction to
With the rapid development of Internet , Web based applications are becoming more and more popular , It's also becoming more and more complex , In order to meet all kinds of needs , Will often store a large amount of data locally ,HTML5 The specification puts forward relevant solutions
Local storage features
- The data is stored in the user's browser
- Set up 、 Easy to read 、 Set page refresh without losing data
- Relatively large capacity ,window.sessionStorage、window.localStorage about 20M
- Only strings can be stored , You can put objects JSON.stringify() Store after encoding
Two 、 sessionStorage
- The lifecycle is to close the browser window
- In the same window ( page ) Next, data can be shared
- Store and use in the form of key value pairs
1、 grammar
Store the data
sessionStorage.setItem(key, value);
get data
sessionStorage.getItem(key);
Delete data
sessionStorage.removeItem(key);
Empty data
sessionStorage.clear();
2、 Case study
<input type="text" name="name" id="" placeholder=" Please enter your name ">
<button class="set"> Store the data </button>
<button class="get"> get data </button>
<button class="remove"> Delete data </button>
<button class="del"> Clear all data </button>
<script>
var ipt = document.querySelector("input");
var set = document.querySelector(".set");
set.addEventListener("click", function() {
// When we click , You can store the data in the form
sessionStorage.setItem(String(Date.now()), ipt.value);
ipt.value = "";
})
var get = document.querySelector(".get");
get.addEventListener("click", function() {
// When we click , You can get the values in the form
alert(sessionStorage.getItem("uName"));
})
var remove = document.querySelector(".remove");
remove.addEventListener("click", function() {
// When we click , You can remove specific values from the form
sessionStorage.removeItem("uName");
})
var del = document.querySelector(".del");
del.addEventListener("click", function() {
// When we click , You can clear all the data in the form
sessionStorage.clear();
})
</script>
3、 ... and 、 localStorage
- The life cycle takes effect permanently , Unless you delete , Otherwise, the closed page will always exist
- You can have multiple windows ( page ) share ( The same browser can share )
- Store in the form of key value pairs
1、 grammar
Store the data
localStorage.setItem(key, value);
get data
localStorage.getItem(key);
Delete data
localStorage.removeItem(key);
Empty data
localStorage.clear();
边栏推荐
- 单例模式的实现
- Classes and objects -- Inheritance
- Musk's "meta universe" dream
- [51nod p2102] or subtraction and [bit operation]
- GPIO of hardware schematic diagram
- Instruction level parallelism (?)
- Node-RED系列(二七):扩展节点之s7节点的使用说明
- (dp+ memory) acwing 901 skiing
- [51nod p3395] n-bit gray code [bit operation]
- [ssl1271] sort I [heap]
猜你喜欢

Exploitation of competitive loopholes in attacking and defending world PWN play conditions

UNIX Environment advanced programming --3-file io---3.10 file sharing

Classes and objects -- Inheritance

(dp+ memory) acwing 901 skiing
![[51nod p3395] n-bit gray code [bit operation]](/img/91/e127e68ae2897933b795414d50c70f.jpg)
[51nod p3395] n-bit gray code [bit operation]
![1-4 message passing interface [CSP authentication]](/img/db/aecda548693cdfb0e740bcf1a1c823.jpg)
1-4 message passing interface [CSP authentication]

(bfs) acwing 847. Hierarchy of points in the graph
![[51nod 2493] sum of binary distances [bit operation]](/img/e9/8a8393f41cac7c323712c34f4d3e01.jpg)
[51nod 2493] sum of binary distances [bit operation]

Classes and objects -- polymorphic

Pxxx local socket communication
随机推荐
I have summarized the knowledge points of JS [intermediate and advanced] for you
[51nod p3058] Xiao ming'ai set [set]
Exercise 7-7 string replacement (15 points)
(dfs) acwing 842. Arrange numbers
Queue and stack
The turtle library displays the system time
[implementation of depth first search]
Trees and binary trees: Construction of binary trees
(dfs+ pruning + checkerboard problem +dood) acwing 843 N-queen problem
Tree and binary tree: application of binary tree traversal
Node-RED系列(二五):集成高德地图并实现3d地图和轨迹回放
@Value does not take effect and extend/implement other classes cannot inject beans manually
7-3 virus traceability (20 points)
Jenkins access openldap user authentication
Can the operation of the new BMW I3 meet the expectations of the famous products of the 3 series?
拜登:希望尽快签署两党枪支安全改革法案
Learning makefile with me
Classes and objects -- Inheritance
Analysis and implementation of variable parameters in C language
Jenkins集成Ldap,Ldap配置错误导致jenkins用户登录失败问题解决