回答編集履歴

3

補足

2016/09/13 09:07

投稿

yambejp
yambejp

スコア114883

test CHANGED
@@ -127,3 +127,121 @@
127
127
  </table>
128
128
 
129
129
  ```
130
+
131
+
132
+
133
+ # 補足
134
+
135
+ ※idをきちんとつければ複数でもいけるはず
136
+
137
+ (古いIEを除く)
138
+
139
+ ```CSS
140
+
141
+ .on-off{display:none;}
142
+
143
+ input[type="checkbox"].on-off + table>tbody{display:none;}
144
+
145
+ input[type="checkbox"].on-off:checked + table>tbody{display:table;}
146
+
147
+
148
+
149
+ ```
150
+
151
+ ```HTML
152
+
153
+ <input type="checkbox" id="Panel1" class="on-off">
154
+
155
+ <table class="menu" width=100>
156
+
157
+ <caption class="class">
158
+
159
+ <label for="Panel1">メニューa</label>
160
+
161
+ </caption>
162
+
163
+ <tbody>
164
+
165
+ <tr>
166
+
167
+ <th>1</th>
168
+
169
+ <td>メニュー1</td>
170
+
171
+ </tr>
172
+
173
+ <tr>
174
+
175
+ <th>2</th>
176
+
177
+ <td>メニュー2</td>
178
+
179
+ </tr>
180
+
181
+ </tbody>
182
+
183
+ </table><input type="checkbox" id="Panel2" class="on-off">
184
+
185
+ <table class="menu" width=100>
186
+
187
+ <caption class="class">
188
+
189
+ <label for="Panel2">メニューb</label>
190
+
191
+ </caption>
192
+
193
+ <tbody>
194
+
195
+ <tr>
196
+
197
+ <th>1</th>
198
+
199
+ <td>メニュー1</td>
200
+
201
+ </tr>
202
+
203
+ <tr>
204
+
205
+ <th>2</th>
206
+
207
+ <td>メニュー2</td>
208
+
209
+ </tr>
210
+
211
+ </tbody>
212
+
213
+ </table>
214
+
215
+ <input type="checkbox" id="Panel3" class="on-off">
216
+
217
+ <table class="menu" width=100>
218
+
219
+ <caption class="class">
220
+
221
+ <label for="Panel3">メニューc</label>
222
+
223
+ </caption>
224
+
225
+ <tbody>
226
+
227
+ <tr>
228
+
229
+ <th>1</th>
230
+
231
+ <td>メニュー1</td>
232
+
233
+ </tr>
234
+
235
+ <tr>
236
+
237
+ <th>2</th>
238
+
239
+ <td>メニュー2</td>
240
+
241
+ </tr>
242
+
243
+ </tbody>
244
+
245
+ </table>
246
+
247
+ ```

2

追記2

2016/09/13 09:07

投稿

yambejp
yambejp

スコア114883

test CHANGED
@@ -71,3 +71,59 @@
71
71
 
72
72
 
73
73
  ```
74
+
75
+
76
+
77
+ # 追記2
78
+
79
+ 確実でなくてよければ以下が近いかも
80
+
81
+ セレクタの解釈などブラウザの違いが吸収しきれませんが
82
+
83
+ とくにIEなどはbehavior:expression()など使わないとダメかもしれません
84
+
85
+ ```css
86
+
87
+ .on-off{display:none;}
88
+
89
+ input[type="checkbox"].on-off + table>tbody{display:none;}
90
+
91
+ input[type="checkbox"].on-off:checked + table>tbody{display:table;}
92
+
93
+ ```
94
+
95
+ ```HTML
96
+
97
+ <input type="checkbox" id="Panel1" class="on-off">
98
+
99
+ <table class="menu" width=100>
100
+
101
+ <caption class="class">
102
+
103
+ <label for="Panel1">メニュー</label>
104
+
105
+ </caption>
106
+
107
+ <tbody>
108
+
109
+ <tr>
110
+
111
+ <th>1</th>
112
+
113
+ <td>メニュー1</td>
114
+
115
+ </tr>
116
+
117
+ <tr>
118
+
119
+ <th>2</th>
120
+
121
+ <td>メニュー2</td>
122
+
123
+ </tr>
124
+
125
+ </tbody>
126
+
127
+ </table>
128
+
129
+ ```

1

追記

2016/09/12 03:11

投稿

yambejp
yambejp

スコア114883

test CHANGED
@@ -3,3 +3,71 @@
3
3
  処理を入れれば可能だと思いますが
4
4
 
5
5
  マークアップの原則から考えればやるべきではありません
6
+
7
+
8
+
9
+ # 追記
10
+
11
+ ちなみにメニューだと考えず単にテーブルの表示/非表示をcaptionで行うという趣旨なら
12
+
13
+ こんな感じでどうでしょう?
14
+
15
+
16
+
17
+ ```HTML
18
+
19
+ <table width=100>
20
+
21
+ <caption class="class">メニュー</caption>
22
+
23
+ <tbody>
24
+
25
+ <tr>
26
+
27
+ <th>1</th>
28
+
29
+ <td>メニュー1</td>
30
+
31
+ </tr>
32
+
33
+ <tr>
34
+
35
+ <th>2</th>
36
+
37
+ <td>メニュー2</td>
38
+
39
+ </tr>
40
+
41
+ </tbody>
42
+
43
+ </table>
44
+
45
+ ```
46
+
47
+ - tableの幅を指定しておかないとcaptionがずれる
48
+
49
+ - javascriptでtableを操作するときにはブラウザごとの誤差を抑えるために
50
+
51
+ theadやtbodyはなるべく明示してください
52
+
53
+
54
+
55
+ ```javascript
56
+
57
+ $(function(){
58
+
59
+ $('.class').siblings().css('display','none');
60
+
61
+ $('.class').click(function(){
62
+
63
+ var disp=$(this).siblings().css('display');
64
+
65
+ $(this).siblings().css('display',disp=='none'?'':'none');
66
+
67
+ });
68
+
69
+ });
70
+
71
+
72
+
73
+ ```