回答編集履歴
2
調整
test
CHANGED
@@ -315,3 +315,75 @@
|
|
315
315
|
</table>
|
316
316
|
|
317
317
|
```
|
318
|
+
|
319
|
+
|
320
|
+
|
321
|
+
# 特定の列を表示しない
|
322
|
+
|
323
|
+
ちょうどhideクラスを作ってあるので、それをthやtdに指定してやる
|
324
|
+
|
325
|
+
場合によってはnth-childなどで指定してもいいが構造が変わるとずれるので微妙
|
326
|
+
|
327
|
+
```HTML
|
328
|
+
|
329
|
+
<table id="t1">
|
330
|
+
|
331
|
+
<thead>
|
332
|
+
|
333
|
+
<tr>
|
334
|
+
|
335
|
+
<th>名前</th>
|
336
|
+
|
337
|
+
<th>色</th>
|
338
|
+
|
339
|
+
<th>種類</th>
|
340
|
+
|
341
|
+
<th class="hide">旬</th>
|
342
|
+
|
343
|
+
</tr>
|
344
|
+
|
345
|
+
</thead>
|
346
|
+
|
347
|
+
<tbody>
|
348
|
+
|
349
|
+
<tr>
|
350
|
+
|
351
|
+
<td>みかん</td>
|
352
|
+
|
353
|
+
<td class="color">オレンジ</td>
|
354
|
+
|
355
|
+
<td class="kind">果物</td>
|
356
|
+
|
357
|
+
<td class="season hide">冬</td>
|
358
|
+
|
359
|
+
</tr>
|
360
|
+
|
361
|
+
<tr>
|
362
|
+
|
363
|
+
<td>りんご</td>
|
364
|
+
|
365
|
+
<td class="color">赤</td>
|
366
|
+
|
367
|
+
<td class="kind">果物</td>
|
368
|
+
|
369
|
+
<td class="season hide">秋・冬</td>
|
370
|
+
|
371
|
+
</tr>
|
372
|
+
|
373
|
+
<tr>
|
374
|
+
|
375
|
+
<td>にんじん</td>
|
376
|
+
|
377
|
+
<td class="color">オレンジ</td>
|
378
|
+
|
379
|
+
<td class="kind">野菜</td>
|
380
|
+
|
381
|
+
<td class="season hide">冬・春</td>
|
382
|
+
|
383
|
+
</tr>
|
384
|
+
|
385
|
+
</tbody>
|
386
|
+
|
387
|
+
</table>
|
388
|
+
|
389
|
+
```
|
1
拡張
test
CHANGED
@@ -146,6 +146,172 @@
|
|
146
146
|
|
147
147
|
</tbody>
|
148
148
|
|
149
|
-
</table>
|
149
|
+
</table>
|
150
150
|
|
151
151
|
```
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
# 3つ以上拡張
|
156
|
+
|
157
|
+
部分一致なので、複数季節をかいてもヒットする
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
```javascript<style>
|
162
|
+
|
163
|
+
.hide{display:none;}
|
164
|
+
|
165
|
+
</style>
|
166
|
+
|
167
|
+
<script>
|
168
|
+
|
169
|
+
window.addEventListener('DOMContentLoaded', function(e){
|
170
|
+
|
171
|
+
var c=["color","kind","season"]; /* ここにクラスを追加する */
|
172
|
+
|
173
|
+
[].forEach.call(document.querySelectorAll(c.map(function(x){
|
174
|
+
|
175
|
+
return "."+x;
|
176
|
+
|
177
|
+
}).join(",")),function(x){
|
178
|
+
|
179
|
+
x.addEventListener('change',function(e){
|
180
|
+
|
181
|
+
var search={};
|
182
|
+
|
183
|
+
c.forEach(function(x){
|
184
|
+
|
185
|
+
search[x]=[].map.call(document.querySelectorAll('[type=checkbox].'+x+':checked'),function(x){
|
186
|
+
|
187
|
+
return x.value;
|
188
|
+
|
189
|
+
});
|
190
|
+
|
191
|
+
});
|
192
|
+
|
193
|
+
var len={};
|
194
|
+
|
195
|
+
var reg={};
|
196
|
+
|
197
|
+
Object.keys(search).forEach(function(x){
|
198
|
+
|
199
|
+
len[x]=search[x].length;
|
200
|
+
|
201
|
+
reg[x]=new RegExp(search[x].join("|"));
|
202
|
+
|
203
|
+
});
|
204
|
+
|
205
|
+
[].forEach.call(document.querySelectorAll('#t1 tbody tr'),function(x){
|
206
|
+
|
207
|
+
var flg=c.map(function(y){
|
208
|
+
|
209
|
+
if(len[y]==0) return true;
|
210
|
+
|
211
|
+
return x.querySelector('td.'+y).textContent.match(reg[y])?true:false;
|
212
|
+
|
213
|
+
}).filter(function(y){
|
214
|
+
|
215
|
+
return !y;
|
216
|
+
|
217
|
+
}).length>0;
|
218
|
+
|
219
|
+
flg?x.classList.add("hide"):x.classList.remove("hide");
|
220
|
+
|
221
|
+
});
|
222
|
+
|
223
|
+
});
|
224
|
+
|
225
|
+
});
|
226
|
+
|
227
|
+
});
|
228
|
+
|
229
|
+
</script>
|
230
|
+
|
231
|
+
<div>色:
|
232
|
+
|
233
|
+
<label><input type="checkbox" value="オレンジ" class="color">オレンジ</label>
|
234
|
+
|
235
|
+
<label><input type="checkbox" value="赤" class="color">赤</label>
|
236
|
+
|
237
|
+
</div>
|
238
|
+
|
239
|
+
<div>種類:
|
240
|
+
|
241
|
+
<label><input type="checkbox" value="果物" class="kind">果物</label>
|
242
|
+
|
243
|
+
<label><input type="checkbox" value="野菜" class="kind">野菜</label>
|
244
|
+
|
245
|
+
</div>
|
246
|
+
|
247
|
+
<div>旬:
|
248
|
+
|
249
|
+
<label><input type="checkbox" value="春" class="season">春</label>
|
250
|
+
|
251
|
+
<label><input type="checkbox" value="夏" class="season">夏</label>
|
252
|
+
|
253
|
+
<label><input type="checkbox" value="秋" class="season">秋</label>
|
254
|
+
|
255
|
+
<label><input type="checkbox" value="冬" class="season">冬</label>
|
256
|
+
|
257
|
+
</div>
|
258
|
+
|
259
|
+
<table id="t1">
|
260
|
+
|
261
|
+
<thead>
|
262
|
+
|
263
|
+
<tr>
|
264
|
+
|
265
|
+
<th>名前</th>
|
266
|
+
|
267
|
+
<th>色</th>
|
268
|
+
|
269
|
+
<th>種類</th>
|
270
|
+
|
271
|
+
</tr>
|
272
|
+
|
273
|
+
</thead>
|
274
|
+
|
275
|
+
<tbody>
|
276
|
+
|
277
|
+
<tr>
|
278
|
+
|
279
|
+
<td>みかん</td>
|
280
|
+
|
281
|
+
<td class="color">オレンジ</td>
|
282
|
+
|
283
|
+
<td class="kind">果物</td>
|
284
|
+
|
285
|
+
<td class="season">冬</td>
|
286
|
+
|
287
|
+
</tr>
|
288
|
+
|
289
|
+
<tr>
|
290
|
+
|
291
|
+
<td>りんご</td>
|
292
|
+
|
293
|
+
<td class="color">赤</td>
|
294
|
+
|
295
|
+
<td class="kind">果物</td>
|
296
|
+
|
297
|
+
<td class="season">秋・冬</td>
|
298
|
+
|
299
|
+
</tr>
|
300
|
+
|
301
|
+
<tr>
|
302
|
+
|
303
|
+
<td>にんじん</td>
|
304
|
+
|
305
|
+
<td class="color">オレンジ</td>
|
306
|
+
|
307
|
+
<td class="kind">野菜</td>
|
308
|
+
|
309
|
+
<td class="season">冬・春</td>
|
310
|
+
|
311
|
+
</tr>
|
312
|
+
|
313
|
+
</tbody>
|
314
|
+
|
315
|
+
</table>
|
316
|
+
|
317
|
+
```
|