当前位置:网站首页>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();
边栏推荐
- 多线程 从UE4的无锁队列开始 (线程安全)
- Britain introduces food security plan to resist food supply crisis
- 二叉树简介
- @Value does not take effect and extend/implement other classes cannot inject beans manually
- WIN7无法被远程桌面问题
- 递归想法和实现介绍,消除递归
- Classes and objects -- polymorphic
- 7-3 virus traceability (20 points)
- 删除软链接
- (dfs) acwing 842. Arrange numbers
猜你喜欢
Tree and binary tree: application of binary tree traversal
LeetCode 1. Sum of two numbers
[51nod p2527] or and sum [bit operation]
(dp+ memory) acwing 901 skiing
Heap
1-2 24:00 (20 points) [CSP certification true question]
(topological sorting +bfs) acwing 848 Topological sequence of digraph
(Dijkstra + shortest circuit + by point n^2) acwing 849 Dijkstra finding the shortest path I
The rise of cloud computing enterprises and the shaking of Oracle database market dominance
(tree DP) acwing 285 A dance without a boss
随机推荐
[51nod P3210] binary statistics
Attack and defense world PWN shell
Calculate the number of days between two times (supports cross month and cross year)
Class and object -- friend
Sort() sort function
Jenkins接入Openldap用戶認證
Summary of string, vector and array learning
多线程 从UE4的无锁队列开始 (线程安全)
[Luogu p1090, ssl1040] merged fruit [pile]
matlab轮毂电机分析模糊pid控制垂向振动分析
MOOC week 8 programming exercise 1
LeetCode 6095. Strong password checker II
Smart210 uses SD card to burn uboot
Acwing785. quick sort (sort+ quick sort + merge sort)
Summary of random number learning
第一章 第一节
Tree and binary tree: storage structure of binary tree
Can the operation of the new BMW I3 meet the expectations of the famous products of the 3 series?
Amadahl's Law (a little thought)
MySQL事务隔离级别和MVCC