質問編集履歴

1

【TaskList】取消線ボタンを実現させたい。

2019/08/13 09:15

投稿

kikuchi1992
kikuchi1992

スコア2

test CHANGED
@@ -1 +1 @@
1
- タスクリストの取消線を表示したい
1
+ 【TaskList】取消線ボタン実現させたい
test CHANGED
@@ -1,34 +1,26 @@
1
- ### 前提・実現したいこと
2
-
3
-
4
-
5
- ここに質問の内容く書いください
1
+ TaskList作成しております
6
-
2
+
7
- (例)HTML/JavaScript)でタスクリスト作っていま
3
+ inputの入力フォームにタスクを入力ると、そのすぐ直下にタスクが表示され、
8
-
4
+
9
- 削除は上手くいきますが、取消線表示させるのが上手くいきせん
5
+ タスクの横にゴミ箱マークと取消線マークが表示さ
6
+
10
-
7
+ ゴミ箱マークをクリックすると削除され、取消線マークをクリックするとタスクに取消線が入るようにしたいです。
8
+
9
+ 今現在は、ゴミ箱マークをクリックすると削除はされますが、取消線マークをクリックしても取消線が表示されません。。
10
+
11
- 初学者のため、無知で恥ずのですが、ご教授ください。
11
+ 初学者のため至らない点があると思すが、ご教授ください。
12
-
13
-
14
-
15
- ### 発生している問題・エラーメッセージ
12
+
16
-
17
-
18
-
19
- ```
13
+
20
-
21
- エラーメッセージ
14
+
22
-
23
- ```
15
+
24
-
25
-
26
-
16
+
17
+
18
+
19
+
20
+
27
- ### 該当のソースコード
21
+ todolist.html
28
-
29
-
30
-
31
- ```javascript
22
+
23
+
32
24
 
33
25
  <!DOCTYPE html>
34
26
 
@@ -42,236 +34,300 @@
42
34
 
43
35
  <title>TASKLIST</title>
44
36
 
45
- <!-- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.2/css/bulma.min.css">-->
46
-
47
37
  <link rel="stylesheet" href="style.css">
48
38
 
49
39
  <script defer src="https://use.fontawesome.com/releases/v5.3.1/js/all.js"></script>
50
40
 
51
- <style>
52
-
53
- .container {
41
+ </head>
42
+
43
+ <body>
44
+
45
+
46
+
47
+ <div class="title">
48
+
49
+ <a class="TASK" href="todolist.html">
50
+
51
+ TaskList
52
+
53
+ </a>
54
+
55
+ </div>
56
+
57
+
58
+
59
+ <section class="section">
60
+
61
+ <div class="container">
62
+
63
+ <div class="field">
64
+
65
+ <p class="controlExpanded">
66
+
67
+ <input id="task" class="input" type="text" placeholder="タスクリストを追加しよう!">
68
+
69
+ </p>
70
+
71
+ <p class="control">
72
+
73
+ <a id="add" class="button">追加</a>
74
+
75
+ </p>
76
+
77
+ </div>
78
+
79
+ <nav class="panel">
80
+
81
+ <div id="todos"></div>
82
+
83
+
84
+
85
+ </nav>
86
+
87
+ </div>
88
+
89
+ </section>
90
+
91
+
92
+
93
+ <script>
94
+
95
+ function get_todos() {
96
+
97
+ var todos = new Array;
98
+
99
+ var todos_str = localStorage.getItem('todo');
100
+
101
+ if (todos_str !== null) {
102
+
103
+ todos = JSON.parse(todos_str);
104
+
105
+ }
106
+
107
+ return todos;
108
+
109
+ }
110
+
111
+
112
+
113
+ function add() {
114
+
115
+ var task = document.getElementById('task').value;
116
+
117
+
118
+
119
+ var todos = get_todos();
120
+
121
+ todos.push(task);
122
+
123
+ localStorage.setItem('todo', JSON.stringify(todos));
124
+
125
+ show();
126
+
127
+
128
+
129
+ return false;
130
+
131
+ }
132
+
133
+
134
+
135
+ function remove() {
136
+
137
+ var id = this.getAttribute('id');
138
+
139
+ var todos = get_todos();
140
+
141
+ todos.splice(id, 1);
142
+
143
+ localStorage.setItem('todo', JSON.stringify(todos));
144
+
145
+
146
+
147
+ show();
148
+
149
+
150
+
151
+ return false;
152
+
153
+ }
154
+
155
+
156
+
157
+ function strike() {
158
+
159
+ var id = this.getAttribute('id');
160
+
161
+ var todos = get_todos();
162
+
163
+
164
+
165
+ document.write(str.strike());
166
+
167
+ }
168
+
169
+
170
+
171
+ function show() {
172
+
173
+ var todos = get_todos();
174
+
175
+
176
+
177
+ var html = '';
178
+
179
+ for(var i=0; i<todos.length; i++) {
180
+
181
+ html += '<a class="panel-block"><span class="panel-icon remove" id="' + i + '"><br>' + todos[i] + '\t \t<i class="fas fa-trash-alt" aria-hidden="true"></i>' + '</span>' + '<span class="panel-icon strike">' + '\t<i class="fas fa-strikethrough" aria-hidden="true"></i>' + '</span></a>';
182
+
183
+ };
184
+
185
+ html += '';
186
+
187
+
188
+
189
+ document.getElementById('todos').innerHTML = html;
190
+
191
+ document.getElementById('task').value ="";
192
+
193
+
194
+
195
+ //削除ボタン
196
+
197
+ var buttons = document.getElementsByClassName('remove');
198
+
199
+ for (var i=0; i < buttons.length; i++) {
200
+
201
+ buttons[i].addEventListener('click', remove);
202
+
203
+ };
204
+
205
+
206
+
207
+ // 取り消し線
208
+
209
+ var buttons = document.getElementsByClassName('strike');
210
+
211
+ for (var i=0; i < buttons.length; i++) {
212
+
213
+ buttons[i].addEventListener('click', line-through);
214
+
215
+ };
216
+
217
+ }
218
+
219
+
220
+
221
+ document.getElementById('add').addEventListener('click', add);
222
+
223
+ show();
224
+
225
+ </script>
226
+
227
+
228
+
229
+ </body>
230
+
231
+ </html>
232
+
233
+
234
+
235
+
236
+
237
+
238
+
239
+
240
+
241
+ style.css
242
+
243
+
244
+
245
+ @import url('https://fonts.googleapis.com/css?family=Raleway&display=swap');
246
+
247
+
248
+
249
+ body{
250
+
251
+ background-image: url(bg-flower.jpg);
252
+
253
+ background-repeat: no-repeat;
254
+
255
+ width:100%;
256
+
257
+ }
258
+
259
+ .container {
54
260
 
55
261
  margin: 0 auto;
56
262
 
57
263
  max-width: 400px;
58
264
 
59
- }
60
-
61
- </style>
62
-
63
- </head>
64
-
65
- <body>
66
-
67
-
68
-
69
-
70
-
71
- <!-- <nav class="navbar has-background-info">-->
72
-
73
- <div class="title">
74
-
75
- <a class="TASK" href="todolist.html">
76
-
77
- TaskList
78
-
79
- </a>
80
-
81
- </div>
82
-
83
- <!-- </nav>-->
84
-
85
-
86
-
87
- <section class="section">
88
-
89
- <div class="container">
90
-
91
- <div class="field">
92
-
93
- <p class="controlExpanded">
94
-
95
- <input id="task" class="input" type="text" placeholder="タスクリストを追加しよう!">
96
-
97
- </p>
98
-
99
- <p class="control">
100
-
101
- <a id="add" class="button">追加</a>
102
-
103
- </p>
104
-
105
- </div>
106
-
107
- <nav class="panel">
108
-
109
- <div id="todos"></div>
110
-
111
-
112
-
113
- </nav>
114
-
115
- </div>
116
-
117
- </section>
118
-
119
-
120
-
121
- <script>
122
-
123
- function get_todos() {
124
-
125
- var todos = new Array;
126
-
127
- var todos_str = localStorage.getItem('todo');
128
-
129
- if (todos_str !== null) {
130
-
131
- todos = JSON.parse(todos_str);
132
-
133
- }
134
-
135
- return todos;
136
-
137
- }
138
-
139
-
140
-
141
- function add() {
142
-
143
- var task = document.getElementById('task').value;
144
-
145
-
146
-
147
- var todos = get_todos();
148
-
149
- todos.push(task);
150
-
151
- localStorage.setItem('todo', JSON.stringify(todos));
152
-
153
- show();
154
-
155
-
156
-
157
- return false;
158
-
159
- }
160
-
161
-
162
-
163
- function remove() {
164
-
165
- var id = this.getAttribute('id');
166
-
167
- var todos = get_todos();
168
-
169
- todos.splice(id, 1);
170
-
171
- localStorage.setItem('todo', JSON.stringify(todos));
172
-
173
-
174
-
175
- show();
176
-
177
-
178
-
179
- return false;
180
-
181
- }
182
-
183
-
184
-
185
- function strike() {
186
-
187
- var id = this.getAttribute('id');
188
-
189
- var todos = get_todos();
190
-
191
-
192
-
193
- document.write(str.strike());
194
-
195
- }
196
-
197
-
198
-
199
- function show() {
200
-
201
- var todos = get_todos();
202
-
203
-
204
-
205
- var html = '';
206
-
207
- for(var i=0; i<todos.length; i++) {
208
-
209
- html += '<a class="panel-block"><span class="panel-icon remove" id="' + i + '"><br>' + todos[i] + '\t \t<i class="fas fa-trash-alt" aria-hidden="true"></i>' + '</span>' + '<span class="panel-icon strike">' + '\t<i class="fas fa-strikethrough" aria-hidden="true"></i>' + '</span></a>';
210
-
211
- };
212
-
213
- html += '';
214
-
215
-
216
-
217
- document.getElementById('todos').innerHTML = html;
218
-
219
- document.getElementById('task').value ="";
220
-
221
-
222
-
223
- //削除ボタン
224
-
225
- var buttons = document.getElementsByClassName('remove');
226
-
227
- for (var i=0; i < buttons.length; i++) {
228
-
229
- buttons[i].addEventListener('click', remove);
230
-
231
- };
265
+ }
266
+
267
+
268
+
269
+ .title{
270
+
271
+ margin:0 auto;
272
+
273
+ text-align: center;
232
274
 
233
275
 
234
276
 
235
- // 取り消し線
236
-
237
- var buttons = document.getElementsByClassName('strike');
238
-
239
- for (var i=0; i < buttons.length; i++) {
240
-
241
- buttons[i].addEventListener('click', line-through);
242
-
243
- };
244
-
245
- }
277
+ }
278
+
246
-
279
+ .TASK{
280
+
247
-
281
+ text-decoration: none;
248
-
282
+
249
- document.getElementById('add').addEventListener('click', add);
283
+ font-family: 'Raleway', sans-serif;
284
+
250
-
285
+ color:#555555;
286
+
287
+ font-size:30px;
288
+
289
+ }
290
+
251
- show();
291
+ .field{
292
+
252
-
293
+ display: flex;
294
+
295
+ margin:0 auto;
296
+
253
- </script>
297
+ text-align: center;
298
+
254
-
299
+ justify-content: center;
255
-
256
-
300
+
257
- </body>
301
+ padding-top: 180px;
302
+
303
+
304
+
258
-
305
+ }
306
+
307
+ .controlExpanded{
308
+
259
- </html>
309
+ margin-right:20px;
260
-
310
+
261
- ```
311
+ }
262
-
263
-
264
-
312
+
265
- ### 試したこと
313
+ .button{
266
-
267
-
268
-
269
- ここに問題に対して試したことを記載してください。
314
+
270
-
271
-
272
-
273
- ### 補足情報(FW/ツールのバージョンなど)
315
+ border:solid 0.5px #555555;
274
-
275
-
276
-
316
+
277
- ここにより詳細な情報を記載してください。
317
+ border-radius: 5px;
318
+
319
+ padding: 3px;
320
+
321
+ }
322
+
323
+ .panel{
324
+
325
+ color:#555555;
326
+
327
+ }
328
+
329
+ .input{
330
+
331
+ width: 150px;
332
+
333
+ }