-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathex 12-2.html
More file actions
38 lines (37 loc) · 1.14 KB
/
Copy pathex 12-2.html
File metadata and controls
38 lines (37 loc) · 1.14 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
36
37
38
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>세션 스토리지에 쓰기/읽기</title>
</head>
<body>
<h3>세션 스토리지에 구입 리스트 저장/검색</h3>
<hr>
품목명 : <input id="item" type="text" size="10">
개수 : <input id="count" type="text" size="10">
<button type="button" id="save" onclick="store()">저장</button>
<button type="button" id="retrieve" onclick="retrieve()">검색</button>
<script>
let item = document.getElementById("item");
let count = document.getElementById("count");
function store() {
if (!window.sessionStorage) {
alert("세션 스토리지를 지원하지 않습니다.");
return;
}
sessionStorage.setItem(item.value, count.value);
}
function retrieve() {
if (!window.sessionStorage) {
alert("세션 스토리지를 지원하지 않습니다.");
return;
}
let val = sessionStorage.getItem(item.value);
if(val == null)
alert(item.value + "는 구입 리스트에 없습니다.");
else
count.value = val;
}
</script>
</body>
</html>