質問編集履歴
1
コードを変更しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -12,8 +12,79 @@
|
|
12
12
|

|
13
13
|
### 発生している問題・エラーメッセージ
|
14
14
|
|
15
|
+
```HTML
|
16
|
+
<!DOCTYPE html>
|
17
|
+
<html>
|
18
|
+
<head>
|
19
|
+
<meta carset="UTF-8">
|
20
|
+
<title>ToDoリスト</title>
|
21
|
+
<link rel="stylesheet" href="style.css">
|
22
|
+
</head>
|
23
|
+
<body>
|
15
24
|
|
25
|
+
<h1>ToDoリスト</h1>
|
26
|
+
|
27
|
+
<div class="form-box">
|
28
|
+
<table class="form">
|
29
|
+
<tr>
|
30
|
+
<th>予定</th>
|
31
|
+
<td><input id="todo" type="text" placeholder="予定を入力" value="予定"></td>
|
32
|
+
<th>日時</th>
|
33
|
+
<td><input id="date" type="datetime-local"></td>
|
34
|
+
</tr>
|
35
|
+
<tr>
|
36
|
+
<th>お金</th>
|
37
|
+
<td><input id="price" type="text" placeholder="金額を入力" value="10000"></td>
|
38
|
+
<th>期日</th>
|
39
|
+
<td><input id="duedate" type="datetime-local"></td>
|
40
|
+
</tr>
|
41
|
+
<tr>
|
42
|
+
<th>持ち物</th>
|
43
|
+
<td><input id="item" type="text" value="持ち物"></td>
|
44
|
+
<th>メモ</th>
|
45
|
+
<td><input id="memo" type="text" value="めもです"></td>
|
46
|
+
</tr>
|
47
|
+
</table>
|
48
|
+
<div id="addButton"><button type="submit">登録する</button></div>
|
49
|
+
<div id="clearButton"><button type="submit" onclick="deleteCheck()" >選択削除</button></div>
|
50
|
+
<div id="allclearButton"><button type="submit" onclick="deleteAll()">すべて削除</button></div>
|
51
|
+
</div>
|
52
|
+
|
53
|
+
<table class="main-table" id="table">
|
54
|
+
<tr id="table-header">
|
55
|
+
<th class="header-check"></th>
|
56
|
+
<th class="header-id">ID</th>
|
57
|
+
<th class="header-todo">予定</th>
|
58
|
+
<th class="header-date">日時</th>
|
59
|
+
<th class="header-price">お金</th>
|
60
|
+
<th class="header-duedate">期日</th>
|
61
|
+
<th class="header-item">持ち物</th>
|
62
|
+
<th class="header-memo">メモ</th>
|
63
|
+
<th class="header-check"></th>
|
64
|
+
</tr>
|
65
|
+
</table>
|
66
|
+
|
67
|
+
<script src="app.js"></script>
|
68
|
+
</body>
|
69
|
+
</html>
|
70
|
+
|
71
|
+
```
|
16
72
|
```JavaScript
|
73
|
+
var j = 1;
|
74
|
+
document.getElementById("addButton").onclick = function(){
|
75
|
+
const todo =document.getElementById('todo').value//予定
|
76
|
+
const date =document.getElementById('date').value//日時
|
77
|
+
const price =document.getElementById('price').value//お金
|
78
|
+
const duedate =document.getElementById('duedate').value//期日
|
79
|
+
const item =document.getElementById('item').value//持ち物
|
80
|
+
const memo =document.getElementById('memo').value//メモ
|
81
|
+
|
82
|
+
let todolists = [todo,date,price,duedate,item,memo];
|
83
|
+
console.log(todolists);
|
84
|
+
mainTable = document.querySelector('.main-table')// テーブル要素を取得する
|
85
|
+
row = mainTable.insertRow(-1) //テーブルに行を追加してその行を返す
|
86
|
+
todolists.unshift(j);
|
87
|
+
|
17
88
|
for (var i = 0; i < 7; i++){
|
18
89
|
cell = row.insertCell(-1) //行に <td> を追加して、その<td>を返す
|
19
90
|
cell.textContent = todolists[i] // <td>内にテキストを入れる。
|
@@ -26,11 +97,27 @@
|
|
26
97
|
console.log(j);
|
27
98
|
}
|
28
99
|
|
100
|
+
// 削除用配列
|
29
101
|
let ch = [];
|
30
102
|
function selectRow(obj) {
|
31
103
|
// 削除ボタンを押下された行配列に追加
|
32
104
|
ch.push(obj);
|
33
105
|
}
|
106
|
+
|
107
|
+
function deleteRow(obj) {
|
108
|
+
// 削除ボタンを押下された行を取得
|
109
|
+
tr = obj.parentNode.parentNode;
|
110
|
+
// trのインデックスを取得して行を削除する
|
111
|
+
tr.parentNode.deleteRow(tr.sectionRowIndex);
|
112
|
+
}
|
113
|
+
|
114
|
+
// function deleteCheck() {
|
115
|
+
// var table = document.getElementById("table");
|
116
|
+
// var rowLen = table.rows.length;
|
117
|
+
// if(rowLen = true){
|
118
|
+
// table.deleteRow(this);
|
119
|
+
// }
|
120
|
+
// };
|
34
121
|
document.getElementById("clearButton").onclick = function(){
|
35
122
|
deleteSelect();
|
36
123
|
}
|
@@ -43,6 +130,16 @@
|
|
43
130
|
}
|
44
131
|
ch = [];
|
45
132
|
}
|
133
|
+
|
134
|
+
|
135
|
+
function deleteAll() {
|
136
|
+
var table = document.getElementById("table");
|
137
|
+
var rowLen = table.rows.length;
|
138
|
+
for (var i = rowLen-1; i > 0; i--) {
|
139
|
+
table.deleteRow(i);
|
140
|
+
}
|
141
|
+
};
|
142
|
+
|
46
143
|
```
|
47
144
|
|
48
145
|
|