-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlocalStorage.html
More file actions
35 lines (33 loc) · 1.12 KB
/
localStorage.html
File metadata and controls
35 lines (33 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
2<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>1
<button id="btn1">11111221221333人1121222223111222111存数据</button>
<button id="btn2">读取www数2据</button>
<button id="btn3">删除数据</button>
<button id="btn4">清空数据</button>
<script>
let person = {name : 'zhangsan', age : 18};
let btn1 = document.getElementById('btn1');
let btn2 = document.getElementById('btn2');
let btn3 = document.getElementById('btn3');
let btn4 = document.getElementById('btn4');
btn1.onclick = function(){
localStorage.setItem('personone', JSON.stringify(person));
};
btn2.onclick = function(){
console.log(JSON.parse(localStorage.getItem('personone')));
};
btn3.onclick = function(){
localStorage.removeItem('personone');
};
btn4.onclick = function(){
localStorage.clear();
};
</script>
</body>
</html>