-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathscript.js
More file actions
30 lines (28 loc) · 1.1 KB
/
script.js
File metadata and controls
30 lines (28 loc) · 1.1 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
const todoList = document.getElementById("todo-list");
const todoInput = document.getElementById("todo-input");
const addButton = document.getElementById("add-button");
todoInput.oninput = () => {
addButton.disabled = todoInput.value === "";
};
addButton.onclick = () => {
const todoItem = document.createElement("li");
const todoText = document.createElement("span");
const editButton = document.createElement("button");
const deleteButton = document.createElement("button");
todoText.textContent = todoInput.value;
todoInput.value = "";
addButton.disabled = true; // value への代入は oninput イベントを発火しない
editButton.textContent = "編集";
editButton.onclick = () => {
const input = prompt("新しい内容を入力してください。");
if (input !== "" && input !== null) todoText.textContent = input;
};
deleteButton.textContent = "削除";
deleteButton.onclick = () => {
todoList.removeChild(todoItem);
};
todoItem.appendChild(todoText);
todoItem.appendChild(editButton);
todoItem.appendChild(deleteButton);
todoList.appendChild(todoItem);
};