質問編集履歴

1

書式の改善

2019/12/01 07:08

投稿

asako1010
asako1010

スコア50

test CHANGED
File without changes
test CHANGED
@@ -143,3 +143,159 @@
143
143
  </html>
144
144
 
145
145
  ```
146
+
147
+
148
+
149
+
150
+
151
+ 【追記】
152
+
153
+
154
+
155
+ ```HTML
156
+
157
+ comment = document.getElementById(id_text.value);
158
+
159
+
160
+
161
+ comment = document.getElementById(id_text).value;
162
+
163
+ ```
164
+
165
+ 上記の変更を加えてもTypeError: Cannot read property 'value' of null
166
+
167
+ と表示されてしまいます。
168
+
169
+ なぜnullになるのでしょうか?
170
+
171
+
172
+
173
+
174
+
175
+ ```HTML
176
+
177
+ <!DOCTYPE html>
178
+
179
+ <html lang="ja">
180
+
181
+ <head>
182
+
183
+ <meta charset="UTF-8">
184
+
185
+ <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
186
+
187
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
188
+
189
+ <title>ToDoリスト</title>
190
+
191
+ <link rel="stylesheet" href="css/styles.css">
192
+
193
+
194
+
195
+ </head>
196
+
197
+ <body>
198
+
199
+ <h1>ToDoリスト</h1>
200
+
201
+
202
+
203
+ <div class="radiobutton">
204
+
205
+ <input type="radio" id="button-1" name="radio1" value="1" checked />
206
+
207
+ <label for="button-1">すべて</label>
208
+
209
+ <input type="radio" id="button-2" name="radio1" value="2" />
210
+
211
+ <label for="button-2">完了中</label>
212
+
213
+ <input type="radio" id="button-3" name="radio1" value="3" />
214
+
215
+ <label for="button-3">作業中</label>
216
+
217
+
218
+
219
+
220
+
221
+ <h3 id="id_h3">ID コメント 状態</h3>
222
+
223
+ <div id="todo"></div>
224
+
225
+ <h2>新規タスクの増加</h2>
226
+
227
+
228
+
229
+ <p id = id_p>
230
+
231
+ <input type="text" id="id_text" value="">
232
+
233
+ <button id="btn" type="btn" class="button"> 追加</button>
234
+
235
+ </p>
236
+
237
+ </div>
238
+
239
+
240
+
241
+ <script>
242
+
243
+ let id = 0;
244
+
245
+ const btn = document.getElementById('btn');
246
+
247
+ btn.addEventListener('click', () => {
248
+
249
+
250
+
251
+ const idEl = document.createElement("span");
252
+
253
+ idEl.textContent = id;
254
+
255
+ const comment = document.getElementById(id_text).value;
256
+
257
+ const commentEl = document.createElement("span");
258
+
259
+ commentEl.textContent = (comment);
260
+
261
+
262
+
263
+ const btn1El = document.createElement("button");
264
+
265
+ btn1El.textContent = "作業中";
266
+
267
+ const btn2El = document.createElement("button");
268
+
269
+ btn2El.textContent = "削除";
270
+
271
+
272
+
273
+ const divEl = document.createElement("div");
274
+
275
+ divEl.appendChild(idEl);
276
+
277
+ divEl.appendChild(commentEl);
278
+
279
+ divEl.appendChild(btn1El);
280
+
281
+ divEl.appendChild(btn2El);
282
+
283
+
284
+
285
+ const todoEl = document.getElementById("todo");
286
+
287
+ todoEl.appendChild(divEl);
288
+
289
+ id++;
290
+
291
+ }, false);
292
+
293
+
294
+
295
+ </script>
296
+
297
+ </body>
298
+
299
+ </html>
300
+
301
+ ```