Skip to content

Commit 0d5fb11

Browse files
committed
prompt
1 parent e667ceb commit 0d5fb11

File tree

3 files changed

+12
-60
lines changed

3 files changed

+12
-60
lines changed

docs/2-browser-apps/06-project/_samples/step3/script.js

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,7 @@ addButton.onclick = () => {
1111
todoInput.value = "";
1212
editButton.textContent = "編集";
1313
editButton.onclick = () => {
14-
const input = document.createElement("input");
15-
const confirmButton = document.createElement("button");
16-
input.value = todoText.textContent;
17-
confirmButton.textContent = "確定";
18-
confirmButton.onclick = () => {
19-
todoText.textContent = input.value;
20-
todoItem.replaceChild(todoText, input);
21-
todoItem.replaceChild(editButton, confirmButton);
22-
};
23-
todoItem.replaceChild(input, todoText);
24-
todoItem.replaceChild(confirmButton, editButton);
14+
todoText.textContent = prompt("編集内容を入力してください");
2515
};
2616
deleteButton.textContent = "削除";
2717
deleteButton.onclick = () => {
@@ -31,4 +21,4 @@ addButton.onclick = () => {
3121
todoItem.appendChild(editButton);
3222
todoItem.appendChild(deleteButton);
3323
todoList.appendChild(todoItem);
34-
};
24+
};
Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
const todoList = document.getElementById("todo-list");
22
const todoInput = document.getElementById("todo-input");
33
const addButton = document.getElementById("add-button");
4-
todoInput.oninput = () => {
5-
addButton.disabled = todoInput.value === "";
6-
};
4+
5+
todoInput.oninput = () => (addButton.disabled = todoInput === "");
76

87
addButton.onclick = () => {
9-
addButton.disabled = true;
108
const todoItem = document.createElement("li");
119
const todoText = document.createElement("span");
1210
const editButton = document.createElement("button");
@@ -15,20 +13,8 @@ addButton.onclick = () => {
1513
todoInput.value = "";
1614
editButton.textContent = "編集";
1715
editButton.onclick = () => {
18-
const input = document.createElement("input");
19-
const confirmButton = document.createElement("button");
20-
input.value = todoText.textContent;
21-
input.oninput = () => {
22-
confirmButton.disabled = input.value === "";
23-
};
24-
confirmButton.textContent = "確定";
25-
confirmButton.onclick = () => {
26-
todoText.textContent = input.value;
27-
todoItem.replaceChild(todoText, input);
28-
todoItem.replaceChild(editButton, confirmButton);
29-
};
30-
todoItem.replaceChild(input, todoText);
31-
todoItem.replaceChild(confirmButton, editButton);
16+
const input = prompt("編集内容を入力してください");
17+
if (input !== "") todoText.textContent = input;
3218
};
3319
deleteButton.textContent = "削除";
3420
deleteButton.onclick = () => {
@@ -38,4 +24,4 @@ addButton.onclick = () => {
3824
todoItem.appendChild(editButton);
3925
todoItem.appendChild(deleteButton);
4026
todoList.appendChild(todoItem);
41-
};
27+
};

docs/2-browser-apps/06-project/index.mdx

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -220,17 +220,7 @@ addButton.onclick = () => {
220220
todoInput.value = "";
221221
editButton.textContent = "編集";
222222
editButton.onclick = () => {
223-
const input = document.createElement("input");
224-
const confirmButton = document.createElement("button");
225-
input.value = todoText.textContent;
226-
confirmButton.textContent = "確定";
227-
confirmButton.onclick = () => {
228-
todoText.textContent = input.value;
229-
todoItem.replaceChild(todoText, input);
230-
todoItem.replaceChild(editButton, confirmButton);
231-
};
232-
todoItem.replaceChild(input, todoText);
233-
todoItem.replaceChild(confirmButton, editButton);
223+
todoText.textContent = prompt("編集内容を入力してください");
234224
};
235225
deleteButton.textContent = "削除";
236226
deleteButton.onclick = () => {
@@ -285,12 +275,10 @@ todoInput.oninput = () => {
285275
const todoList = document.getElementById("todo-list");
286276
const todoInput = document.getElementById("todo-input");
287277
const addButton = document.getElementById("add-button");
288-
todoInput.oninput = () => {
289-
addButton.disabled = todoInput.value === "";
290-
};
278+
279+
todoInput.oninput = () => (addButton.disabled = todoInput === "");
291280

292281
addButton.onclick = () => {
293-
addButton.disabled = true;
294282
const todoItem = document.createElement("li");
295283
const todoText = document.createElement("span");
296284
const editButton = document.createElement("button");
@@ -299,20 +287,8 @@ addButton.onclick = () => {
299287
todoInput.value = "";
300288
editButton.textContent = "編集";
301289
editButton.onclick = () => {
302-
const input = document.createElement("input");
303-
const confirmButton = document.createElement("button");
304-
input.value = todoText.textContent;
305-
input.oninput = () => {
306-
confirmButton.disabled = input.value === "";
307-
};
308-
confirmButton.textContent = "確定";
309-
confirmButton.onclick = () => {
310-
todoText.textContent = input.value;
311-
todoItem.replaceChild(todoText, input);
312-
todoItem.replaceChild(editButton, confirmButton);
313-
};
314-
todoItem.replaceChild(input, todoText);
315-
todoItem.replaceChild(confirmButton, editButton);
290+
const input = prompt("編集内容を入力してください");
291+
if (input !== "") todoText.textContent = input;
316292
};
317293
deleteButton.textContent = "削除";
318294
deleteButton.onclick = () => {

0 commit comments

Comments
 (0)