-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathsimple.html
More file actions
50 lines (47 loc) · 1.45 KB
/
simple.html
File metadata and controls
50 lines (47 loc) · 1.45 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
39
40
41
42
43
44
45
46
47
48
49
50
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Simple TODO List</title>
</head>
<body>
<section id="container">
<h1 class="title">TODO</h1>
<div class="input-container">
<input type="text" class="todo-input" />
<input id="saveTodoBtn" type="button" value="저장" />
</div>
<div class="list-container">
<ul id="todo-list" class="todo-list"></ul>
</div>
</section>
<script>
const $todolist = document.getElementById("todo-list");
const $saveTodoBtn = document.getElementById("saveTodoBtn");
const $todoInput = document.querySelector(".todo-input");
let $liEl;
let inputText;
// 이벤트리스너 바인딩
$todoInput.addEventListener("input", (e) => {
inputText = e.target.value.trim();
});
$todoInput.addEventListener("keydown", (e) => {
if (e.keyCode !== 13) return;
addTodo();
});
$saveTodoBtn.addEventListener("click", (e) => {
addTodo();
});
// 함수선언
const addTodo = () => {
if (!inputText) return;
if (window.confirm(`"${$todoInput.value}" 저장하시겠습니까?`)) {
$liEl = `<li>${inputText}</li>`;
$todolist.insertAdjacentHTML("beforeend", $liEl);
$todoInput.value = "";
}
};
</script>
</body>
</html>