From 94dde86d1557909394d081a12d863b34c1b88ff8 Mon Sep 17 00:00:00 2001 From: 3759357 <94110438+3759357@users.noreply.github.com> Date: Wed, 11 Dec 2024 15:18:59 +0900 Subject: [PATCH 1/3] Update simple.html --- simple.html | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/simple.html b/simple.html index 2887e44..0a76d10 100644 --- a/simple.html +++ b/simple.html @@ -9,8 +9,8 @@

TODO

- - + +
- + + + - + \ No newline at end of file From 1d8a8798249491ef6150ed30ee28ebb7c02088d3 Mon Sep 17 00:00:00 2001 From: 3759357 <94110438+3759357@users.noreply.github.com> Date: Thu, 12 Dec 2024 20:28:11 +0900 Subject: [PATCH 2/3] =?UTF-8?q?[=EC=9B=90=EC=8A=B9=ED=98=81]=20detail.html?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [원승혁] detail.html --- detail.html | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 94 insertions(+), 3 deletions(-) diff --git a/detail.html b/detail.html index 160571b..54fae2b 100644 --- a/detail.html +++ b/detail.html @@ -9,10 +9,10 @@

TODO LIST

- +
- @@ -23,5 +23,96 @@

TODO LIST

- + + From 8bc41bb4a6cc27f0bd5e5353c48a93e586a1b809 Mon Sep 17 00:00:00 2001 From: 3759357 <94110438+3759357@users.noreply.github.com> Date: Fri, 20 Dec 2024 11:56:55 +0900 Subject: [PATCH 3/3] 4-1 --- detail.html | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/detail.html b/detail.html index 54fae2b..c26ceb8 100644 --- a/detail.html +++ b/detail.html @@ -114,5 +114,89 @@

TODO LIST

} }); } + + + window.addEventListener('beforeunload', () => { + const saveItems = []; + for (let i = 0; i < todoList.children.length; i++){ + const todoObj = { + contents: todoList.children[i].querySelector('span').textContent, + complete: todoList.children[i].classList.contains('complete') + }; + saveItems.push(todoObj); + } + localStorage.setItem('saved-items', JSON.stringify(saveItems)); + }); + + + + const savedTodoList = JSON.parse(localStorage.getItem('saved-items')); + console.log(savedTodoList) + + + if (savedTodoList) { // 로컬에서 데이터 가져오기 + for(let i = 0; i < savedTodoList.length; i++){ + const todoText = savedTodoList[i].contents; + const complete = savedTodoList[i].complete; + + const item = document.createElement('div'); + const checkbox = document.createElement('input'); + checkbox.type = 'checkbox'; + checkbox.checked = complete; + const deleteButton = document.createElement('button'); + deleteButton.textContent = "x"; + const updateButton = document.createElement('button'); + updateButton.textContent = "edit"; + + const newTodo = document.createElement('span'); + newTodo.textContent = todoText; + + item.appendChild(checkbox); + item.appendChild(newTodo); + item.appendChild(updateButton); + item.appendChild(deleteButton); + todoList.appendChild(item); + todoInput.value = ''; + checkbox.addEventListener('click', (event) => { + if (event.currentTarget.checked) { + item.setAttribute("data-value", "done"); + } else { + item.setAttribute("data-value", "todo"); + } + }); + + + deleteButton.addEventListener('click', (event) => { + todoList.removeChild(event.currentTarget.parentNode); + }); + + + updateButton.addEventListener('click', (event) => { + const currentText = newTodo.textContent; + const inputField = document.createElement('input'); + inputField.type = 'text'; + inputField.value = currentText; + + + const saveButton = document.createElement('button'); + saveButton.textContent = 'Save'; + + + saveButton.addEventListener('click', () => { + newTodo.textContent = inputField.value; + item.replaceChild(newTodo, inputField); + item.replaceChild(updateButton, saveButton); + }); + + item.replaceChild(inputField, newTodo); + item.replaceChild(saveButton, updateButton); + }); + + + } +} + + +