-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpractice12-2-store.html
More file actions
35 lines (33 loc) · 1.13 KB
/
practice12-2-store.html
File metadata and controls
35 lines (33 loc) · 1.13 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>세션 스토리지에 구입 리스트 저장</title>
<script>
function store() {
const item = document.getElementById("item").value.trim();
const count = document.getElementById("count").value.trim();
if (!window.sessionStorage) {
alert("세션 스토리지를 지원하지 않습니다.");
return;
}
if (item && count) {
sessionStorage.setItem(item, count);
alert(`${item}가 저장되었습니다.`);
} else {
alert("품목명과 개수를 입력해주세요.");
}
}
</script>
</head>
<body>
<h3>세션 스토리지에 구입 리스트 저장</h3>
<hr>
<form>
<label>품목명: <input id="item" type="text" size="10"></label>
<label>개수: <input id="count" type="text" size="10"></label>
<input type="button" value="저장" onclick="store()">
</form>
</body>
</html>