回答編集履歴
2
修正版
test
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
※ダメな回答
|
2
|
+
|
1
3
|
```javascript
|
2
4
|
|
3
5
|
const deleteTask = (taskId) => {
|
@@ -22,4 +24,112 @@
|
|
22
24
|
|
23
25
|
```
|
24
26
|
|
27
|
+
# 修正版
|
28
|
+
|
29
|
+
```javascript
|
30
|
+
|
31
|
+
'use strict';
|
32
|
+
|
33
|
+
{
|
34
|
+
|
35
|
+
const newtask = document.getElementById('newtask');
|
36
|
+
|
37
|
+
const add = document.getElementById('add');
|
38
|
+
|
39
|
+
const deleteTask = (btn) => {
|
40
|
+
|
41
|
+
const task = btn.closest('tr');
|
42
|
+
|
43
|
+
const tbody=task.closest('tbody');
|
44
|
+
|
45
|
+
task.remove();
|
46
|
+
|
47
|
+
tbody.querySelectorAll('tr').forEach((x,y)=>{
|
48
|
+
|
49
|
+
x.setAttribute('id',`id-${y+1}`);
|
50
|
+
|
51
|
+
x.querySelector('td').textContent=y+1;
|
52
|
+
|
53
|
+
});
|
54
|
+
|
55
|
+
id--;
|
56
|
+
|
57
|
+
}
|
58
|
+
|
59
|
+
let id = 0;
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
add.addEventListener('click',() => {
|
64
|
+
|
65
|
+
if(newtask.value =='') {
|
66
|
+
|
67
|
+
return
|
68
|
+
|
69
|
+
}
|
70
|
+
|
71
|
+
id += 1;
|
72
|
+
|
73
|
+
const list = document.getElementById('list')
|
74
|
+
|
75
|
+
const tr = document.createElement('tr')
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
const taskId = `task-${id}`
|
80
|
+
|
81
|
+
tr.id = taskId
|
82
|
+
|
83
|
+
const comment = newtask.value;
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
const workButton = document.createElement('button');
|
88
|
+
|
89
|
+
workButton.innerHTML = '作業中';
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
const deleteButton = document.createElement('button');
|
94
|
+
|
95
|
+
deleteButton.innerHTML = '削除';
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
deleteButton.addEventListener('click', () => deleteTask(deleteButton));
|
100
|
+
|
101
|
+
const cloumns = [id, comment, workButton, deleteButton]
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
cloumns.forEach((cloumn) => {
|
106
|
+
|
107
|
+
const td = document.createElement('td');
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
if (cloumn instanceof HTMLElement) {
|
112
|
+
|
113
|
+
td.appendChild(cloumn)
|
114
|
+
|
115
|
+
} else {
|
116
|
+
|
117
|
+
td.innerText = cloumn;
|
118
|
+
|
119
|
+
}
|
120
|
+
|
121
|
+
tr.appendChild(td);
|
122
|
+
|
123
|
+
|
124
|
+
|
25
|
-
|
125
|
+
})
|
126
|
+
|
127
|
+
list.appendChild(tr);
|
128
|
+
|
129
|
+
newtask.value = ''
|
130
|
+
|
131
|
+
})
|
132
|
+
|
133
|
+
}
|
134
|
+
|
135
|
+
```
|
1
調整
test
CHANGED
@@ -4,11 +4,11 @@
|
|
4
4
|
|
5
5
|
const task = document.getElementById(taskId);
|
6
6
|
|
7
|
-
const
|
7
|
+
const tbody=task.closest('tbody');
|
8
8
|
|
9
9
|
task.remove();
|
10
10
|
|
11
|
-
|
11
|
+
tbody.querySelectorAll('tr').forEach((x,y)=>{
|
12
12
|
|
13
13
|
x.setAttribute('id',`id-${y+1}`);
|
14
14
|
|
@@ -21,3 +21,5 @@
|
|
21
21
|
}
|
22
22
|
|
23
23
|
```
|
24
|
+
|
25
|
+
調整
|