回答編集履歴

7

修正

2016/10/26 00:19

投稿

yambejp
yambejp

スコア114883

test CHANGED
@@ -290,12 +290,24 @@
290
290
 
291
291
  <body>
292
292
 
293
+ <!-- //手書きをプログラムに
294
+
293
295
  <a href="#" onclick="return show_block(1);">表示切替1</a>
294
296
 
295
297
  <a href="#" onclick="return show_block(2);">表示切替2</a>
296
298
 
297
299
  <a href="#" onclick="return show_block(3);">表示切替3</a>
298
300
 
301
+ //-->
302
+
303
+ <?php for($i=1;$i<=count($xml->shop);$i++){
304
+
305
+ print "<a href=\"#\" onclick=\"return show_block({$i});\">表示切替{$i}</a>";
306
+
307
+ }>
308
+
309
+
310
+
299
311
  <?php foreach($xml->shop as $rest){
300
312
 
301
313
  $count++;

6

api版

2016/10/26 00:19

投稿

yambejp
yambejp

スコア114883

test CHANGED
@@ -221,3 +221,131 @@
221
221
  </html>
222
222
 
223
223
  ```
224
+
225
+
226
+
227
+ # なんかよくわからないapiを組み込んだもの
228
+
229
+ ```PHP
230
+
231
+ <?php
232
+
233
+ $key='My Key';
234
+
235
+ $count='10';
236
+
237
+ $large_area='Z011';
238
+
239
+ $start =1;
240
+
241
+ $format='xml';
242
+
243
+ $url='http://webservice.recruit.co.jp/hotpepper/gourmet/v1/?key='.$key.'&count='.$count.'&large_area='.$large_area.'&start='.$start.'&format='.$format;
244
+
245
+ $xml=simplexml_load_file($url);
246
+
247
+ $total_count=$xml->results_available;
248
+
249
+ ?>
250
+
251
+ <?php
252
+
253
+ if(!$xml->shop){
254
+
255
+ echo 'We can not find!!';
256
+
257
+ } else {
258
+
259
+ $count=0;
260
+
261
+ ?>
262
+
263
+ <!DOCTYPE html>
264
+
265
+ <html>
266
+
267
+ <head>
268
+
269
+ <script>
270
+
271
+ function show_block(num){
272
+
273
+ if(document.getElementById("hoge"+num).style.display != "none"){
274
+
275
+ document.getElementById("hoge"+num).style.display = "none";
276
+
277
+ }else{
278
+
279
+ document.getElementById("hoge"+num).style.display = "block";
280
+
281
+ }
282
+
283
+ return false;
284
+
285
+ }
286
+
287
+ </script>
288
+
289
+ </head>
290
+
291
+ <body>
292
+
293
+ <a href="#" onclick="return show_block(1);">表示切替1</a>
294
+
295
+ <a href="#" onclick="return show_block(2);">表示切替2</a>
296
+
297
+ <a href="#" onclick="return show_block(3);">表示切替3</a>
298
+
299
+ <?php foreach($xml->shop as $rest){
300
+
301
+ $count++;
302
+
303
+ ?>
304
+
305
+ <table border="1" class="a" id="hoge<?PHP print $count;?>">
306
+
307
+ <tr>
308
+
309
+ <td>
310
+
311
+ <?php echo $rest->name; ?>
312
+
313
+ </td>
314
+
315
+ </tr>
316
+
317
+ <tr>
318
+
319
+ <td>
320
+
321
+ <?php echo $rest->lng; ?>
322
+
323
+ <?php echo $rest->lat; ?>
324
+
325
+ </td>
326
+
327
+ </tr>
328
+
329
+ <tr>
330
+
331
+ <td>
332
+
333
+ <?php echo $rest->address; ?>
334
+
335
+ </td>
336
+
337
+ </tr>
338
+
339
+ </table>
340
+
341
+ <?php }?>
342
+
343
+ </body>
344
+
345
+ </html>
346
+
347
+ <?php }?>
348
+
349
+
350
+
351
+ ```

5

調整

2016/10/25 14:14

投稿

yambejp
yambejp

スコア114883

test CHANGED
@@ -156,7 +156,7 @@
156
156
 
157
157
  function show_block(num){
158
158
 
159
- var t=document.getElementsByTagName("table");
159
+ var t=document.getElementById("hoge").getElementsByTagName("table");
160
160
 
161
161
  if(t[num].style.display!="none"){
162
162
 
@@ -168,8 +168,6 @@
168
168
 
169
169
  }
170
170
 
171
- return false;
172
-
173
171
  }
174
172
 
175
173
  </script>
@@ -184,6 +182,8 @@
184
182
 
185
183
  <a href="#" onclick="return show_block(2);">表示切替3</a>
186
184
 
185
+ <div id="hoge">
186
+
187
187
  <table border>
188
188
 
189
189
  <tr>
@@ -214,6 +214,8 @@
214
214
 
215
215
  </table>
216
216
 
217
+ </div>
218
+
217
219
  </body>
218
220
 
219
221
  </html>

4

typo

2016/10/25 13:12

投稿

yambejp
yambejp

スコア114883

test CHANGED
@@ -168,6 +168,8 @@
168
168
 
169
169
  }
170
170
 
171
+ return false;
172
+
171
173
  }
172
174
 
173
175
  </script>

3

追記

2016/10/25 13:09

投稿

yambejp
yambejp

スコア114883

test CHANGED
@@ -141,3 +141,79 @@
141
141
  </html>
142
142
 
143
143
  ```
144
+
145
+
146
+
147
+ # idをつかわずに順番だけで判断
148
+
149
+ ```HTML
150
+
151
+ <html>
152
+
153
+ <head>
154
+
155
+ <script>
156
+
157
+ function show_block(num){
158
+
159
+ var t=document.getElementsByTagName("table");
160
+
161
+ if(t[num].style.display!="none"){
162
+
163
+ t[num].style.display="none";
164
+
165
+ }else{
166
+
167
+ t[num].style.display="";
168
+
169
+ }
170
+
171
+ }
172
+
173
+ </script>
174
+
175
+ </head>
176
+
177
+ <body>
178
+
179
+ <a href="#" onclick="return show_block(0);">表示切替1</a>
180
+
181
+ <a href="#" onclick="return show_block(1);">表示切替2</a>
182
+
183
+ <a href="#" onclick="return show_block(2);">表示切替3</a>
184
+
185
+ <table border>
186
+
187
+ <tr>
188
+
189
+ <td>name1</td>
190
+
191
+ </tr>
192
+
193
+ </table>
194
+
195
+ <table border>
196
+
197
+ <tr>
198
+
199
+ <td>name2</td>
200
+
201
+ </tr>
202
+
203
+ </table>
204
+
205
+ <table border>
206
+
207
+ <tr>
208
+
209
+ <td>name3</td>
210
+
211
+ </tr>
212
+
213
+ </table>
214
+
215
+ </body>
216
+
217
+ </html>
218
+
219
+ ```

2

追記

2016/10/25 13:08

投稿

yambejp
yambejp

スコア114883

test CHANGED
@@ -51,3 +51,93 @@
51
51
  </html>
52
52
 
53
53
  ```
54
+
55
+
56
+
57
+ # 複数件数
58
+
59
+ 複数件数バージョンを追記します
60
+
61
+ ```HTML
62
+
63
+ <html>
64
+
65
+ <head>
66
+
67
+ <script>
68
+
69
+ function show_block(num){
70
+
71
+ if(document.getElementById("hoge"+num).style.display != "none"){
72
+
73
+ document.getElementById("hoge"+num).style.display = "none";
74
+
75
+ }else{
76
+
77
+ document.getElementById("hoge"+num).style.display = "block";
78
+
79
+ }
80
+
81
+ return false;
82
+
83
+ }
84
+
85
+ </script>
86
+
87
+ </head>
88
+
89
+ <body>
90
+
91
+ <a href="#" onclick="return show_block(1);">表示切替1</a>
92
+
93
+ <a href="#" onclick="return show_block(2);">表示切替2</a>
94
+
95
+ <a href="#" onclick="return show_block(3);">表示切替3</a>
96
+
97
+ <div id="hoge1" style="display:none;">
98
+
99
+ <table border>
100
+
101
+ <tr>
102
+
103
+ <td>name1</td>
104
+
105
+ </tr>
106
+
107
+ </table>
108
+
109
+ </div>
110
+
111
+ <div id="hoge2" style="display:none;">
112
+
113
+ <table border>
114
+
115
+ <tr>
116
+
117
+ <td>name2</td>
118
+
119
+ </tr>
120
+
121
+ </table>
122
+
123
+ </div>
124
+
125
+ <div id="hoge3" style="display:none;">
126
+
127
+ <table border>
128
+
129
+ <tr>
130
+
131
+ <td>name3</td>
132
+
133
+ </tr>
134
+
135
+ </table>
136
+
137
+ </div>
138
+
139
+ </body>
140
+
141
+ </html>
142
+
143
+ ```

1

修正

2016/10/25 12:56

投稿

yambejp
yambejp

スコア114883

test CHANGED
@@ -1,4 +1,12 @@
1
+ とりあえず、HTMLも含めて
2
+
3
+ ```HTML
4
+
5
+ <html>
6
+
7
+ <head>
8
+
1
- ```javascript
9
+ <script>
2
10
 
3
11
  function show_block(){
4
12
 
@@ -12,8 +20,34 @@
12
20
 
13
21
  }
14
22
 
23
+ return false;
24
+
15
25
  }
16
26
 
27
+ </script>
17
28
 
29
+ </head>
30
+
31
+ <body>
32
+
33
+ <a href="#" onclick="return show_block();">表示切替</a>
34
+
35
+ <div id="hoge" style="display:none;">
36
+
37
+ <table border>
38
+
39
+ <tr>
40
+
41
+ <td><?php echo $r->food->name; ?></td>
42
+
43
+ </tr>
44
+
45
+ </table>
46
+
47
+ </div>
48
+
49
+ </body>
50
+
51
+ </html>
18
52
 
19
53
  ```