回答編集履歴
3
追記2
answer
CHANGED
@@ -105,3 +105,47 @@
|
|
105
105
|
</tbody>
|
106
106
|
</table>
|
107
107
|
```
|
108
|
+
|
109
|
+
# 単純なクリックによる表示・非表示
|
110
|
+
menuクラスのついたtableのcaptionをクリックする度にtbodyを切り替えるだけでいいなら
|
111
|
+
こうしてください
|
112
|
+
```javascript
|
113
|
+
$(function(){
|
114
|
+
$('table.menu caption').on('click',function(){
|
115
|
+
$(this).nextAll('tbody').first().toggle();
|
116
|
+
});
|
117
|
+
});
|
118
|
+
```
|
119
|
+
|
120
|
+
```HTML
|
121
|
+
<table class="menu" width=300>
|
122
|
+
<caption>
|
123
|
+
test caption 1
|
124
|
+
</caption>
|
125
|
+
<tbody>
|
126
|
+
<tr>
|
127
|
+
<th>
|
128
|
+
アクセス
|
129
|
+
</th>
|
130
|
+
<td>
|
131
|
+
test access 1
|
132
|
+
</td>
|
133
|
+
</tr>
|
134
|
+
</tbody>
|
135
|
+
</table>
|
136
|
+
<table class="menu" width=300>
|
137
|
+
<caption>
|
138
|
+
test caption 2
|
139
|
+
</caption>
|
140
|
+
<tbody style="display:none">
|
141
|
+
<tr>
|
142
|
+
<th>
|
143
|
+
アクセス
|
144
|
+
</th>
|
145
|
+
<td>
|
146
|
+
test access 2
|
147
|
+
</td>
|
148
|
+
</tr>
|
149
|
+
</tbody>
|
150
|
+
</table>
|
151
|
+
```
|
2
CSS
answer
CHANGED
@@ -58,4 +58,50 @@
|
|
58
58
|
|
59
59
|
```
|
60
60
|
|
61
|
-
チェックボックス自体はcssで非表示にして構いません
|
61
|
+
チェックボックス自体はcssで非表示にして構いません
|
62
|
+
|
63
|
+
# css
|
64
|
+
以前書いたのはCSS版
|
65
|
+
|
66
|
+
```CSS
|
67
|
+
input.Panel{display:none;}
|
68
|
+
input.Panel:checked + table > tbody {display:none;}
|
69
|
+
```
|
70
|
+
```HTML
|
71
|
+
<input type="checkbox" id="Panel1" class="Panel">
|
72
|
+
<table class="menu" width=300>
|
73
|
+
<caption>
|
74
|
+
<label for="Panel1">
|
75
|
+
test caption 1
|
76
|
+
</label>
|
77
|
+
</caption>
|
78
|
+
<tbody>
|
79
|
+
<tr>
|
80
|
+
<th>
|
81
|
+
アクセス
|
82
|
+
</th>
|
83
|
+
<td>
|
84
|
+
test access 1
|
85
|
+
</td>
|
86
|
+
</tr>
|
87
|
+
</tbody>
|
88
|
+
</table>
|
89
|
+
<input type="checkbox" id="Panel2" class="Panel" checked>
|
90
|
+
<table class="menu" width=300>
|
91
|
+
<caption>
|
92
|
+
<label for="Panel2">
|
93
|
+
test caption 2
|
94
|
+
</label>
|
95
|
+
</caption>
|
96
|
+
<tbody>
|
97
|
+
<tr>
|
98
|
+
<th>
|
99
|
+
アクセス
|
100
|
+
</th>
|
101
|
+
<td>
|
102
|
+
test access 2
|
103
|
+
</td>
|
104
|
+
</tr>
|
105
|
+
</tbody>
|
106
|
+
</table>
|
107
|
+
```
|
1
追記
answer
CHANGED
@@ -2,4 +2,60 @@
|
|
2
2
|
HTMLだけで書き直してください
|
3
3
|
不要なtdやtrの閉じタグもありHTML自体を正しく書くところから始めてください
|
4
4
|
|
5
|
-
なおご要望としてはキャプションをクリックしてtbodyを表示・非表示すればいいのでしょうか?
|
5
|
+
なおご要望としてはキャプションをクリックしてtbodyを表示・非表示すればいいのでしょうか?
|
6
|
+
|
7
|
+
# 追記
|
8
|
+
チェックボックスに保持していいのでしたらidを指定してつけたり消したりしなくてもよいのでは?
|
9
|
+
|
10
|
+
```javascript
|
11
|
+
$(function(){
|
12
|
+
$('.Panel').each(function(){
|
13
|
+
if($(this).prop('checked')) $(this).nextAll('table.menu').first().find('tbody').hide();
|
14
|
+
});
|
15
|
+
$('.Panel').on('change',function(){
|
16
|
+
$(this).nextAll('table.menu').first().find('tbody').toggle();
|
17
|
+
});
|
18
|
+
});
|
19
|
+
```
|
20
|
+
|
21
|
+
```HTML
|
22
|
+
<input type="checkbox" id="Panel1" class="Panel">
|
23
|
+
<table class="menu" width=300>
|
24
|
+
<caption>
|
25
|
+
<label for="Panel1">
|
26
|
+
test caption 1
|
27
|
+
</label>
|
28
|
+
</caption>
|
29
|
+
<tbody>
|
30
|
+
<tr>
|
31
|
+
<th>
|
32
|
+
アクセス
|
33
|
+
</th>
|
34
|
+
<td>
|
35
|
+
test access 1
|
36
|
+
</td>
|
37
|
+
</tr>
|
38
|
+
</tbody>
|
39
|
+
</table>
|
40
|
+
<input type="checkbox" id="Panel2" class="Panel" checked>
|
41
|
+
<table class="menu" width=300>
|
42
|
+
<caption>
|
43
|
+
<label for="Panel2">
|
44
|
+
test caption 2
|
45
|
+
</label>
|
46
|
+
</caption>
|
47
|
+
<tbody>
|
48
|
+
<tr>
|
49
|
+
<th>
|
50
|
+
アクセス
|
51
|
+
</th>
|
52
|
+
<td>
|
53
|
+
test access 2
|
54
|
+
</td>
|
55
|
+
</tr>
|
56
|
+
</tbody>
|
57
|
+
</table>
|
58
|
+
|
59
|
+
```
|
60
|
+
|
61
|
+
チェックボックス自体はcssで非表示にして構いません
|