回答編集履歴

2

省略できるところがあったので消す

2021/02/26 10:24

投稿

babu_babu_baboo
babu_babu_baboo

スコア616

test CHANGED
@@ -26,19 +26,19 @@
26
26
 
27
27
  <body>
28
28
 
29
- <table border="1" id="LIST" >
29
+ <table border="1" id="LIST">
30
30
 
31
31
  <thead>
32
32
 
33
33
  <tr>
34
34
 
35
+ <th>No.
36
+
35
- <th>No.</th>
37
+ <th>追加/削除
36
-
37
- <th>追加/削除</th>
38
+
38
-
39
- <th>選択肢1</th>
39
+ <th>選択肢1
40
-
40
+
41
- <th>選択肢2</th>
41
+ <th>選択肢2
42
42
 
43
43
 
44
44
 
@@ -92,8 +92,6 @@
92
92
 
93
93
  </select>
94
94
 
95
- </td>
96
-
97
95
  </table>
98
96
 
99
97
 

1

寝ぼけていたので修正

2021/02/26 10:24

投稿

babu_babu_baboo
babu_babu_baboo

スコア616

test CHANGED
@@ -8,39 +8,23 @@
8
8
 
9
9
  <!DOCTYPE html>
10
10
 
11
- <html lang="ja">
11
+ <meta charset="UTF-8">
12
-
13
- <head>
12
+
14
-
15
- <title>sample</title>
13
+ <title>sample</title>
16
-
17
- <meta charset="UTF-8">
18
14
 
19
15
  <style>
20
16
 
21
- #LIST tbody tr:first-of-type { display: none; }
22
-
23
- #LIST td select optgroup:last-of-type { display: none;}
17
+ #LIST tbody tr:first-of-type, #LIST td select optgroup:last-of-type { display: none;}
24
-
18
+
25
- #LIST { counter-reset: number 0; }
19
+ #LIST { counter-reset: number 0; }
26
-
20
+
27
- #LIST tbody tr th label:after {
21
+ #LIST tbody tr th label:after { counter-increment: number 1; content: counter(number);}
28
-
29
- counter-increment: number 1;
30
-
31
- content: counter(number);
32
-
33
- }
34
22
 
35
23
  </style>
36
24
 
37
25
 
38
26
 
39
- </head>
27
+ <body>
40
-
41
-
42
-
43
-
44
28
 
45
29
  <table border="1" id="LIST" >
46
30
 
@@ -114,12 +98,12 @@
114
98
 
115
99
 
116
100
 
101
+
102
+
117
103
  <script>
118
104
 
119
105
 
120
106
 
121
-
122
-
123
107
  function replaceTRSelects (e) {
124
108
 
125
109
  let
@@ -174,25 +158,11 @@
174
158
 
175
159
 
176
160
 
177
- function addRow (tr) {
161
+ function addRow (tr = null) {
178
-
179
- let
162
+
180
-
181
- [tbody, first] = tr
182
-
183
- ? tr.closest ('table').querySelectorAll ('tbody, tbody tr')
163
+ let tbody = tr ? tr.parentNode: document.querySelector ('#LIST tbody');
184
-
185
- : document.querySelectorAll ('#LIST tbody, #LIST tbody tr'),
164
+
186
-
187
- cFirst = first.cloneNode (true);
188
-
189
-
190
-
191
- (tr)
192
-
193
- ? tbody.insertBefore (cFirst, tr)
165
+ tbody.insertBefore (tbody.rows[0].cloneNode (true), tr);
194
-
195
- : tbody.appendChild (cFirst);
196
166
 
197
167
  }
198
168
 
@@ -262,6 +232,4 @@
262
232
 
263
233
  </script>
264
234
 
265
-
266
-
267
235
  ```