teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

インデントと文字数の兼ね合いでtable項目減らしました。

2020/09/24 14:02

投稿

Miii
Miii

スコア30

title CHANGED
File without changes
body CHANGED
@@ -6,372 +6,235 @@
6
6
  ```html
7
7
  <!DOCTYPE html>
8
8
  <html>
9
- <head>
9
+ <head>
10
- <meta charset="UTF-8">
10
+ <meta charset="UTF-8">
11
- <meta name="robots" content="noindex,nofollow">
11
+ <meta name="robots" content="noindex,nofollow">
12
12
 
13
- <!-- ビューポートの設定 -->
13
+ <!-- ビューポートの設定 -->
14
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
14
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
15
15
 
16
- <!-- スタイルシートの読み込み -->
16
+ <!-- スタイルシートの読み込み -->
17
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
17
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
18
+ <title>デモ</title>
19
+ <style>
20
+ #modal-content{
21
+ max-height: calc(100vh - 1.5em);
22
+ width:50%;
23
+ margin:1.5em auto 0;
24
+ padding:10px 20px;
25
+ border:2px solid #aaa;
26
+ background:#fff;
27
+ z-index:2;
28
+ position:fixed;
29
+ display:none;
30
+ overflow: auto;
31
+ }
18
32
 
33
+ .button-link{
34
+ margin-left : 60px;
35
+ text-align:center;
36
+ -moz-border-radius: 5px;
19
- <title>デモ</title>
37
+ -webkit-border-radius: 5px;
38
+ border-radius: 5px;
39
+ }
20
40
 
21
- </head>
41
+ .button-link:hover{
42
+ cursor:pointer;
22
- <body>
43
+ color:#f00;
44
+ }
23
45
 
46
+ #modal-overlay{
47
+ z-index:1;
48
+ display:none;
49
+ position:fixed;
50
+ top:0;
51
+ left:0;
52
+ width:100%;
53
+ height:120%;
54
+ background-color:rgba(0,0,0,0.75);
55
+ }
56
+ td{
57
+ padding:5px;
58
+ }
59
+ </style>
60
+ </head>
24
61
 
25
- <style>
62
+ <body>
26
- #modal-content{
27
- max-height: calc(100vh - 1.5em);
63
+ <h1 style="text-align:center;color:#d36015;">デモ</h1>
28
64
 
29
- width:50%;
30
- margin:1.5em auto 0;
65
+ <HR style="margin: 3em 0 ;">
31
- padding:10px 20px;
32
- border:2px solid #aaa;
33
- background:#fff;
34
- z-index:2;
35
- position:fixed;
36
- display:none;
37
- overflow: auto;
38
- }
39
66
 
40
- .button-link{
41
- margin-left : 60px;
42
- text-align:center;
43
- -moz-border-radius: 5px;
44
- -webkit-border-radius: 5px;
45
- border-radius: 5px;
46
- }
47
-
48
- .button-link:hover{
49
- cursor:pointer;
50
- color:#f00;
51
- }
52
-
53
- #modal-overlay{
54
- z-index:1;
55
- display:none;
56
- position:fixed;
57
- top:0;
58
- left:0;
59
- width:100%;
60
- height:120%;
61
- background-color:rgba(0,0,0,0.75);
62
- }
63
-
64
- </style>
65
-
66
- <h1 style="text-align:center;color:#d36015;">デモ</h1>
67
-
68
- <HR style="margin: 3em 0 ;">
67
+ <!-- -->
69
-
70
-
71
- <!-- ここからモーダルウィンドウ -->
68
+ <!-- ここからモーダルウィンドウ -->
72
- <div id="modal-content">
73
- <!-- -->
74
69
  <!-- モーダルウィンドウのコンテンツ開始 -->
75
- <!-- -->
70
+ <!-- -->
76
-
77
-
78
71
 
72
+ <div id="modal-content">
73
+ <p><a id="modal-close1" class="button-link">[閉じる]</a></p>
74
+ <form name="childfrm" action="" method="post">
75
+ <input id="btn4444" type="button" value="値を渡す">
76
+ </form>
77
+ <input type="text" id="search"> <input type="button" value="絞り込む" id="button"> <input type="button" value="すべて表示" id="button2">
79
78
 
79
+ <p id="kekka" style="display:none;height:50px;width:300px;text-align:center;"></p>
80
+
81
+ <table id="result" style="border-spacing:0;">
80
- <style>
82
+ <thead>
81
- td{
82
- padding:5px;
83
+ <tr><th>✔️</th><th>列1</th><th>列2</th><th>列3</th><th>列4</th></tr>
83
- }
84
- </style>
84
+ </thead>
85
+ <tbody>
86
+ <tr>
87
+ <td><input type="radio" name="hoge" class="hoge" value="1" /></td>
85
88
 
89
+ <td>地域A</td>
90
+ <td>てすとCCC</td>
91
+ <td>300</td>
92
+ <td>1300</td>
93
+ </tr>
94
+ <tr>
95
+ <td><input type="radio" name="hoge" class="hoge" value="1" /></td>
96
+ <td>地域A</td>
97
+ <td>てすとBBA</td>
98
+ <td>400</td>
99
+ <td>500</td>
100
+ </tr>
101
+ <tr>
102
+ <td><input type="radio" name="hoge" class="hoge" value="1" /></td>
103
+ <td>地域A</td>
104
+ <td>てすとAA</td>
105
+ <td>1000</td>
106
+ <td>2000</td>
107
+ </tr>
108
+
109
+ <tr>
110
+ <td><input type="radio" name="hoge" class="hoge" value="1" /></td>
111
+ <td>地域C</td>
112
+ <td><label style="display:none;">地域CてすとB</label>てすとB</td>
113
+ <td>115</td>
114
+ <td>600</td>
115
+ </tr>
116
+ <tr>
117
+ <td><input type="radio" name="hoge" class="hoge" value="1" /></td>
118
+ <td>地域C</td>
119
+ <td><label style="display:none;">地域CてすとE</label>てすとE</td>
120
+ <td>300</td>
121
+ <td>400</td>
122
+ </tr>
123
+ </tbody>
124
+ </table>
86
125
 
87
- <p><a id="modal-close1" class="button-link">[閉じる]</a></p>
126
+ <p><a id="modal-close2" class="button-link">[閉じる]</a></p>
88
- <form name="childfrm" action="" method="post">
89
-
90
- <input id="btn4444" type="button" value="値を渡す">
91
-
92
- </form>
93
- <input type="text" id="search"> <input type="button" value="絞り込む" id="button"> <input type="button" value="すべて表示" id="button2">
94
-
95
- <p id="kekka" style="display:none;height:50px;width:300px;text-align:center;">
96
- </p>
97
- <table id="result" style="border-spacing:0;">
98
- <thead>
99
-
100
-
101
- <tr><th>✔️</th><th>列1</th><th>列2</th><th>列3</th><th>列4</th></tr>
102
- </thead>
103
-
104
-
105
- <tbody>
106
- <tr>
107
- <td><input type="radio" name="hoge" class="hoge" value="1" /></td>
108
-
109
- <td>地域A</td>
110
- <td>てすとCCC</td>
111
- <td>300</td><td>1300</td>
112
- </tr>
127
+ </div>
113
- <tr>
114
- <td><input type="radio" name="hoge" class="hoge" value="1" /></td>
115
- <td>地域A</td>
128
+ <!-- -->
116
- <td>てすとBBA</td>
129
+ <!-- モーダルウィンドウのコンテンツ終了 -->
117
- <td>400</td><td>500</td>
118
- </tr>
119
- <tr>
120
- <td><input type="radio" name="hoge" class="hoge" value="1" /></td>
121
- <td>地域A</td>
122
- <td>てすとAA</td>
130
+ <!-- -->
123
- <td>1000</td><td>2000</td>
124
- </tr>
125
- <tr>
126
- <td><input type="radio" name="hoge" class="hoge" value="1" /></td>
127
- <td>地域A</td>
128
- <td>てすとD</td>
129
- <td>2000</td><td>1000</td>
130
- </tr>
131
- <tr>
132
- <td><input type="radio" name="hoge" class="hoge" value="1" /></td>
133
- <td>地域B</td>
134
- <td>てすとC</td>
135
- <td>1000</td><td>2000</td>
136
- </tr>
137
- <tr>
138
- <td><input type="radio" name="hoge" class="hoge" value="1" /></td>
139
- <td>地域B</td>
140
- <td>てすとA</td>
141
- <td>1000</td><td>13000</td>
142
- </tr>
143
- <tr>
144
- <td><input type="radio" name="hoge" class="hoge" value="1" /></td>
145
- <td>地域C</td>
146
- <td>てすとB</td>
147
- <td>115</td><td>600</td>
148
- </tr>
149
- <tr>
150
- <td><input type="radio" name="hoge" class="hoge" value="1" /></td>
151
- <td>地域C</td>
152
- <td>てすとE</td>
153
- <td>300</td>
154
- <td>400</td>
155
- </tr>
156
- <tr>
157
- <td><input type="radio" name="hoge" class="hoge" value="1" /></td>
158
- <td>地域C</td>
159
- <td>てすとF</td>
160
- <td>100</td><td>200</td>
161
- </tr>
162
- <tr>
163
- <td><input type="radio" name="hoge" class="hoge" value="1" /></td>
164
- <td>地域C</td>
165
- <td>てすとG</td>
166
- <td>330</td><td>255</td>
167
- </tr> <tr>
168
- <td><input type="radio" name="hoge" class="hoge" value="1" /></td>
169
- <td>地域C</td>
170
- <td>てすとF</td>
171
- <td>100</td><td>200</td>
172
- </tr>
173
- <tr>
174
- <td><input type="radio" name="hoge" class="hoge" value="1" /></td>
175
- <td>地域C</td>
176
- <td>てすとG</td>
177
- <td>130</td><td>250</td>
178
- </tr>
179
- <tr>
180
- <td><input type="radio" name="hoge" class="hoge" value="1" /></td>
181
- <td>地域A</td>
182
- <td>てすとD</td>
183
- <td>2000</td><td>1000</td>
184
- </tr>
185
- <tr>
186
- <td><input type="radio" name="hoge" class="hoge" value="1" /></td>
187
- <td>地域B</td>
188
- <td>てすとC</td>
189
- <td>1000</td><td>2000</td>
190
- </tr>
191
- <tr>
192
- <td><input type="radio" name="hoge" class="hoge" value="1" /></td>
193
- <td>地域B</td>
194
- <td>てすとA</td>
195
- <td>1000</td><td>13000</td>
196
- </tr>
197
- <tr>
198
- <td><input type="radio" name="hoge" class="hoge" value="1" /></td>
199
- <td>地域C</td>
200
- <td><label style="display:none;">地域CてすとB</label>てすとB</td>
201
- <td>115</td><td>600</td>
202
- </tr>
203
- <tr>
204
- <td><input type="radio" name="hoge" class="hoge" value="1" /></td>
205
- <td>地域C</td>
206
- <td><label style="display:none;">地域CてすとE</label>てすとE</td>
207
- <td>300</td><td>400</td>
208
- </tr>
209
- <tr>
210
- </tbody>
211
- </table>
212
-
213
-
214
-
215
131
 
216
132
 
133
+ <p><a id="modal-open" class="button-link">クリックするとモーダルウィンドウを開きます。</a></p>
134
+ <!-- ここまでモーダルウィンドウ -->
217
135
 
136
+ <HR style="margin: 3em 0 ;">
218
137
 
138
+ <p id="subresult1">ここに表示</p>
219
139
 
220
140
 
141
+ <script>
221
142
 
143
+ jQuery(function($){
144
+ //モーダルウィンドウを出現させるクリックイベント
145
+ $("#modal-open").click( function(){
146
+ //キーボード操作などにより、オーバーレイが多重起動するのを防止する
147
+ $( this ).blur() ; //ボタンからフォーカスを外す
148
+ if( $( "#modal-overlay" )[0] ) return false ; //新しくモーダルウィンドウを起動しない (防止策1)
149
+ //if($("#modal-overlay")[0]) $("#modal-overlay").remove() ; //現在のモーダルウィンドウを削除して新しく起動する (防止策2)
222
150
 
223
-
151
+ //オーバーレイを出現させる
224
- <p><a id="modal-close2" class="button-link">[閉じる]</a></p>
152
+ $( "body" ).append( '<div id="modal-overlay"></div>' );
225
- <!-- -->
226
- <!-- モーダルウィンドウのコンテンツ終了 -->
153
+ $( "#modal-overlay" ).fadeIn( "slow" );
227
- <!-- -->
228
- </div>
229
154
 
155
+ //コンテンツをセンタリングする
156
+ centeringModalSyncer();
230
157
 
231
- <p><a id="modal-open" class="button-link">クリックするとモーダルウィンドウを開きます。</a></p>
232
- <!-- ここまでモーダルウィンドウ -->
158
+ //コテンツをフェーインする
159
+ $( "#modal-content" ).fadeIn( "slow" ) ;
233
160
 
161
+ //[#modal-overlay]、または[#modal-close1]や2,btn4444をクリックしたら…
162
+ $( "#modal-overlay,#modal-close1,#modal-close2,#btn4444" ).unbind().click( function(){
163
+ //[#modal-content]と[#modal-overlay]をフェードアウトした後に…
164
+ $( "#modal-content,#modal-overlay" ).fadeOut( "slow" , function(){
165
+ //[#modal-overlay]を削除する
166
+ $('#modal-overlay').remove() ;
167
+ });
168
+ });
169
+ });
234
170
 
171
+ //リサイズされたら、センタリングをする関数[centeringModalSyncer()]を実行する
172
+ $( window ).resize( centeringModalSyncer );
173
+ //センタリングを実行する関数
174
+ function centeringModalSyncer() {
175
+ //画面(ウィンドウ)の幅、高さを取得
176
+ var w = $( window ).width() ;
177
+ var h = $( window ).height() ;
235
178
 
179
+ // コンテンツ(#modal-content)の幅、高さを取得
180
+ // jQueryのバージョンによっては、引数[{margin:true}]を指定した時、不具合を起こします。
181
+ // var cw = $( "#modal-content" ).outerWidth( {margin:true} );
182
+ // var ch = $( "#modal-content" ).outerHeight( {margin:true} );
183
+ var cw = $( "#modal-content" ).outerWidth();
184
+ var ch = $( "#modal-content" ).outerHeight();
236
185
 
186
+ //センタリングを実行する
187
+ $( "#modal-content" ).css( {"left": ((w - cw)/2) + "px","top": ((h - ch)/2) + "px"} ) ;
188
+ }
189
+ });
237
190
 
238
- <HR style="margin: 3em 0 ;">
239
191
 
240
192
 
241
193
 
194
+ document.addEventListener("DOMContentLoaded", () => {
195
+ document.querySelector("#button").addEventListener("click", ()=>{
196
+ var re = new RegExp(document.querySelector('#search').value);
197
+ document.querySelectorAll('#result tbody tr').forEach(el => {
242
- <p id="subresult1">ここに表示</p>
198
+ var txt = el.querySelectorAll("td")[1].innerHTML;
199
+ var txt2 = el.querySelectorAll("td")[2].innerHTML;
243
200
 
201
+ if(txt.match(re) == null && txt2.match(re) == null){
202
+ //el.style.color = "black";
203
+ el.style.display="none";
204
+ }else{
205
+ //el.style.color = "Red";
206
+ el.style.display="table-row";
207
+ }
208
+ });
209
+ });
244
210
 
211
+ document.querySelector("#button2").addEventListener("click", ()=>{
212
+ document.querySelector('#search').value = '';
213
+ // document.querySelectorAll('#result tr').forEach(el => el.style.color = "black");
214
+ document.querySelectorAll('#result tr').forEach(el => el.style.display="table-row");
215
+ });
245
216
 
217
+ document.querySelector("#btn4444").addEventListener("click", ()=>{
218
+ //$("#subresult1").text(window.line);
219
+ function TableSelect (table, x = 1, y = 1) {
220
+ let q = `tr:nth-of-type(${y}) td:nth-of-type(${x})`;
221
+ return table.querySelector (q).textContent;
222
+ }
246
- <script>
223
+ if(window.line==undefined){
224
+ }else{
225
+ $("#subresult1").text(TableSelect(document.querySelector('table'), 5, window.line+1));
226
+ }
227
+ });
247
228
 
229
+ $('input[type="radio"]').change(function() {
230
+ //選択したvalue値を変数に格納
231
+ window.line = $(this).parents('tr').index();
232
+ });
233
+ });
248
- jQuery(function($){
234
+ </script>
249
235
 
250
- //モーダルウィンドウを出現させるクリックイベント
251
- $("#modal-open").click( function(){
252
236
 
253
- //キーボード操作などにより、オーバーレイが多重起動するのを防止する
254
- $( this ).blur() ; //ボタンからフォーカスを外す
255
- if( $( "#modal-overlay" )[0] ) return false ; //新しくモーダルウィンドウを起動しない (防止策1)
256
- //if($("#modal-overlay")[0]) $("#modal-overlay").remove() ; //現在のモーダルウィンドウを削除して新しく起動する (防止策2)
257
-
258
- //オーバーレイを出現させる
259
- $( "body" ).append( '<div id="modal-overlay"></div>' ) ;
260
- $( "#modal-overlay" ).fadeIn( "slow" ) ;
261
-
262
- //コンテンツをセンタリングする
263
- centeringModalSyncer() ;
264
-
265
- //コンテンツをフェードインする
266
- $( "#modal-content" ).fadeIn( "slow" ) ;
267
-
268
- //[#modal-overlay]、または[#modal-close1]や2,btn4444をクリックしたら…
269
- $( "#modal-overlay,#modal-close1,#modal-close2,#btn4444" ).unbind().click( function(){
270
-
271
- //[#modal-content]と[#modal-overlay]をフェードアウトした後に…
272
- $( "#modal-content,#modal-overlay" ).fadeOut( "slow" , function(){
273
-
274
- //[#modal-overlay]を削除する
275
- $('#modal-overlay').remove() ;
276
-
277
- } ) ;
278
-
279
- } ) ;
280
-
281
-
282
- } ) ;
283
-
284
- //リサイズされたら、センタリングをする関数[centeringModalSyncer()]を実行する
285
- $( window ).resize( centeringModalSyncer ) ;
286
-
287
- //センタリングを実行する関数
288
- function centeringModalSyncer() {
289
-
290
- //画面(ウィンドウ)の幅、高さを取得
291
- var w = $( window ).width() ;
292
- var h = $( window ).height() ;
293
-
294
- // コンテンツ(#modal-content)の幅、高さを取得
295
- // jQueryのバージョンによっては、引数[{margin:true}]を指定した時、不具合を起こします。
296
- // var cw = $( "#modal-content" ).outerWidth( {margin:true} );
297
- // var ch = $( "#modal-content" ).outerHeight( {margin:true} );
298
- var cw = $( "#modal-content" ).outerWidth();
299
- var ch = $( "#modal-content" ).outerHeight();
300
-
301
- //センタリングを実行する
302
- $( "#modal-content" ).css( {"left": ((w - cw)/2) + "px","top": ((h - ch)/2) + "px"} ) ;
303
-
304
- }
305
-
306
- } ) ;
307
-
308
-
309
-
310
-
311
- document.addEventListener("DOMContentLoaded", () => {
312
- document.querySelector("#button").addEventListener("click", ()=>{
313
- var re = new RegExp(document.querySelector('#search').value);
314
- document.querySelectorAll('#result tbody tr').forEach(el => {
315
- var txt = el.querySelectorAll("td")[1].innerHTML;
316
- var txt2 = el.querySelectorAll("td")[2].innerHTML;
317
-
318
- if(txt.match(re) == null && txt2.match(re) == null){
319
- //el.style.color = "black";
320
- el.style.display="none";
321
- }else{
322
- //el.style.color = "Red";
323
- el.style.display="table-row";
324
- }
325
- });
326
- });
327
-
328
- document.querySelector("#button2").addEventListener("click", ()=>{
329
- document.querySelector('#search').value = '';
330
- // document.querySelectorAll('#result tr').forEach(el => el.style.color = "black");
331
- document.querySelectorAll('#result tr').forEach(el => el.style.display="table-row");
332
- });
333
-
334
- document.querySelector("#btn4444").addEventListener("click", ()=>{
335
-
336
- //$("#subresult1").text(window.line);
337
-
338
- //選択
339
- function TableSelect (table, x = 1, y = 1) {
340
- let q = `tr:nth-of-type(${y}) td:nth-of-type(${x})`;
341
- return table.querySelector (q).textContent;
342
- }
343
- if(window.line==undefined){
344
- }else{
345
- //5が列4
346
- //console.log (TableSelect(document.querySelector('table'), 5, window.line+1));
347
- $("#subresult1").text(TableSelect(document.querySelector('table'), 5, window.line+1));
348
- }
349
-
350
- });
351
-
352
-
353
- $('input[type="radio"]').change(function() {
354
-
355
- //選択したvalue値を変数に格納
356
- window.line = $(this).parents('tr').index();
357
-
358
-
359
-
360
- });
361
-
362
-
363
-
364
-
365
-
366
- });
367
-
368
- </script>
369
-
370
-
371
-
372
-
373
-
374
- </body>
237
+ </body>
375
238
  </html>
376
239
 
377
240