-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy path2. local-storage.html
37 lines (34 loc) · 1.07 KB
/
2. local-storage.html
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
36
37
<!DOCTYPE html>
<html>
<head>
<title>Local Storage Demo</title>
</head>
<body>
<div>
<input id="key" type="text" placeholder="Insert key" />
<input id="value" type="text" placeholder="Insert value" />
<button id="put-btn">Put in local storage</button>
<button id="get-btn">get from local storage</button>
</div>
<div id="result">
Items: <br/>
</div>
<script>
(function () {
var result = document.getElementById('result');
var button = document.getElementById('put-btn');
button.addEventListener('click', function (e) {
var keyText = document.getElementById('key').value;
var valueText = document.getElementById('value').value;
localStorage.setItem(keyText, valueText);
result.innerHTML += 'Item added: ' + keyText + ' => ' + valueText + '<br />';
});
var getButton = document.getElementById('get-btn');
getButton.addEventListener('click', function (e) {
var keyText = document.getElementById('key').value;
result.innerHTML += keyText + ' => ' + localStorage.getItem(keyText) + '<br />';
});
}())
</script>
</body>
</html>