回答編集履歴

3

追記2

2016/09/28 08:10

投稿

yambejp
yambejp

スコア114960

test CHANGED
@@ -213,3 +213,91 @@
213
213
  ```
214
214
 
215
215
 
216
+
217
+ # 単純なクリックによる表示・非表示
218
+
219
+ menuクラスのついたtableのcaptionをクリックする度にtbodyを切り替えるだけでいいなら
220
+
221
+ こうしてください
222
+
223
+ ```javascript
224
+
225
+ $(function(){
226
+
227
+ $('table.menu caption').on('click',function(){
228
+
229
+ $(this).nextAll('tbody').first().toggle();
230
+
231
+ });
232
+
233
+ });
234
+
235
+ ```
236
+
237
+
238
+
239
+ ```HTML
240
+
241
+ <table class="menu" width=300>
242
+
243
+ <caption>
244
+
245
+ test caption 1
246
+
247
+ </caption>
248
+
249
+ <tbody>
250
+
251
+ <tr>
252
+
253
+ <th>
254
+
255
+ アクセス
256
+
257
+ </th>
258
+
259
+ <td>
260
+
261
+ test access 1
262
+
263
+ </td>
264
+
265
+ </tr>
266
+
267
+ </tbody>
268
+
269
+ </table>
270
+
271
+ <table class="menu" width=300>
272
+
273
+ <caption>
274
+
275
+ test caption 2
276
+
277
+ </caption>
278
+
279
+ <tbody style="display:none">
280
+
281
+ <tr>
282
+
283
+ <th>
284
+
285
+ アクセス
286
+
287
+ </th>
288
+
289
+ <td>
290
+
291
+ test access 2
292
+
293
+ </td>
294
+
295
+ </tr>
296
+
297
+ </tbody>
298
+
299
+ </table>
300
+
301
+ ```
302
+
303
+

2

CSS

2016/09/28 08:10

投稿

yambejp
yambejp

スコア114960

test CHANGED
@@ -119,3 +119,97 @@
119
119
 
120
120
 
121
121
  チェックボックス自体はcssで非表示にして構いません
122
+
123
+
124
+
125
+ # css
126
+
127
+ 以前書いたのはCSS版
128
+
129
+
130
+
131
+ ```CSS
132
+
133
+ input.Panel{display:none;}
134
+
135
+ input.Panel:checked + table > tbody {display:none;}
136
+
137
+ ```
138
+
139
+ ```HTML
140
+
141
+ <input type="checkbox" id="Panel1" class="Panel">
142
+
143
+ <table class="menu" width=300>
144
+
145
+ <caption>
146
+
147
+ <label for="Panel1">
148
+
149
+ test caption 1
150
+
151
+ </label>
152
+
153
+ </caption>
154
+
155
+ <tbody>
156
+
157
+ <tr>
158
+
159
+ <th>
160
+
161
+ アクセス
162
+
163
+ </th>
164
+
165
+ <td>
166
+
167
+ test access 1
168
+
169
+ </td>
170
+
171
+ </tr>
172
+
173
+ </tbody>
174
+
175
+ </table>
176
+
177
+ <input type="checkbox" id="Panel2" class="Panel" checked>
178
+
179
+ <table class="menu" width=300>
180
+
181
+ <caption>
182
+
183
+ <label for="Panel2">
184
+
185
+ test caption 2
186
+
187
+ </label>
188
+
189
+ </caption>
190
+
191
+ <tbody>
192
+
193
+ <tr>
194
+
195
+ <th>
196
+
197
+ アクセス
198
+
199
+ </th>
200
+
201
+ <td>
202
+
203
+ test access 2
204
+
205
+ </td>
206
+
207
+ </tr>
208
+
209
+ </tbody>
210
+
211
+ </table>
212
+
213
+ ```
214
+
215
+

1

追記

2016/09/27 03:18

投稿

yambejp
yambejp

スコア114960

test CHANGED
@@ -7,3 +7,115 @@
7
7
 
8
8
 
9
9
  なおご要望としてはキャプションをクリックしてtbodyを表示・非表示すればいいのでしょうか?
10
+
11
+
12
+
13
+ # 追記
14
+
15
+ チェックボックスに保持していいのでしたらidを指定してつけたり消したりしなくてもよいのでは?
16
+
17
+
18
+
19
+ ```javascript
20
+
21
+ $(function(){
22
+
23
+ $('.Panel').each(function(){
24
+
25
+ if($(this).prop('checked')) $(this).nextAll('table.menu').first().find('tbody').hide();
26
+
27
+ });
28
+
29
+ $('.Panel').on('change',function(){
30
+
31
+ $(this).nextAll('table.menu').first().find('tbody').toggle();
32
+
33
+ });
34
+
35
+ });
36
+
37
+ ```
38
+
39
+
40
+
41
+ ```HTML
42
+
43
+ <input type="checkbox" id="Panel1" class="Panel">
44
+
45
+ <table class="menu" width=300>
46
+
47
+ <caption>
48
+
49
+ <label for="Panel1">
50
+
51
+ test caption 1
52
+
53
+ </label>
54
+
55
+ </caption>
56
+
57
+ <tbody>
58
+
59
+ <tr>
60
+
61
+ <th>
62
+
63
+ アクセス
64
+
65
+ </th>
66
+
67
+ <td>
68
+
69
+ test access 1
70
+
71
+ </td>
72
+
73
+ </tr>
74
+
75
+ </tbody>
76
+
77
+ </table>
78
+
79
+ <input type="checkbox" id="Panel2" class="Panel" checked>
80
+
81
+ <table class="menu" width=300>
82
+
83
+ <caption>
84
+
85
+ <label for="Panel2">
86
+
87
+ test caption 2
88
+
89
+ </label>
90
+
91
+ </caption>
92
+
93
+ <tbody>
94
+
95
+ <tr>
96
+
97
+ <th>
98
+
99
+ アクセス
100
+
101
+ </th>
102
+
103
+ <td>
104
+
105
+ test access 2
106
+
107
+ </td>
108
+
109
+ </tr>
110
+
111
+ </tbody>
112
+
113
+ </table>
114
+
115
+
116
+
117
+ ```
118
+
119
+
120
+
121
+ チェックボックス自体はcssで非表示にして構いません