質問編集履歴
1
書式の改善
title
CHANGED
File without changes
|
body
CHANGED
@@ -70,4 +70,82 @@
|
|
70
70
|
</script>
|
71
71
|
</body>
|
72
72
|
</html>
|
73
|
+
```
|
74
|
+
|
75
|
+
|
76
|
+
【追記】
|
77
|
+
|
78
|
+
```HTML
|
79
|
+
comment = document.getElementById(id_text.value);
|
80
|
+
↓
|
81
|
+
comment = document.getElementById(id_text).value;
|
82
|
+
```
|
83
|
+
上記の変更を加えてもTypeError: Cannot read property 'value' of null
|
84
|
+
と表示されてしまいます。
|
85
|
+
なぜnullになるのでしょうか?
|
86
|
+
|
87
|
+
|
88
|
+
```HTML
|
89
|
+
<!DOCTYPE html>
|
90
|
+
<html lang="ja">
|
91
|
+
<head>
|
92
|
+
<meta charset="UTF-8">
|
93
|
+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
94
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
95
|
+
<title>ToDoリスト</title>
|
96
|
+
<link rel="stylesheet" href="css/styles.css">
|
97
|
+
|
98
|
+
</head>
|
99
|
+
<body>
|
100
|
+
<h1>ToDoリスト</h1>
|
101
|
+
|
102
|
+
<div class="radiobutton">
|
103
|
+
<input type="radio" id="button-1" name="radio1" value="1" checked />
|
104
|
+
<label for="button-1">すべて</label>
|
105
|
+
<input type="radio" id="button-2" name="radio1" value="2" />
|
106
|
+
<label for="button-2">完了中</label>
|
107
|
+
<input type="radio" id="button-3" name="radio1" value="3" />
|
108
|
+
<label for="button-3">作業中</label>
|
109
|
+
|
110
|
+
|
111
|
+
<h3 id="id_h3">ID コメント 状態</h3>
|
112
|
+
<div id="todo"></div>
|
113
|
+
<h2>新規タスクの増加</h2>
|
114
|
+
|
115
|
+
<p id = id_p>
|
116
|
+
<input type="text" id="id_text" value="">
|
117
|
+
<button id="btn" type="btn" class="button"> 追加</button>
|
118
|
+
</p>
|
119
|
+
</div>
|
120
|
+
|
121
|
+
<script>
|
122
|
+
let id = 0;
|
123
|
+
const btn = document.getElementById('btn');
|
124
|
+
btn.addEventListener('click', () => {
|
125
|
+
|
126
|
+
const idEl = document.createElement("span");
|
127
|
+
idEl.textContent = id;
|
128
|
+
const comment = document.getElementById(id_text).value;
|
129
|
+
const commentEl = document.createElement("span");
|
130
|
+
commentEl.textContent = (comment);
|
131
|
+
|
132
|
+
const btn1El = document.createElement("button");
|
133
|
+
btn1El.textContent = "作業中";
|
134
|
+
const btn2El = document.createElement("button");
|
135
|
+
btn2El.textContent = "削除";
|
136
|
+
|
137
|
+
const divEl = document.createElement("div");
|
138
|
+
divEl.appendChild(idEl);
|
139
|
+
divEl.appendChild(commentEl);
|
140
|
+
divEl.appendChild(btn1El);
|
141
|
+
divEl.appendChild(btn2El);
|
142
|
+
|
143
|
+
const todoEl = document.getElementById("todo");
|
144
|
+
todoEl.appendChild(divEl);
|
145
|
+
id++;
|
146
|
+
}, false);
|
147
|
+
|
148
|
+
</script>
|
149
|
+
</body>
|
150
|
+
</html>
|
73
151
|
```
|