前提・実現したいこと
プルダウンメニューの初期表示を特定の時間にしたいのですがうまくいきません
アドバイスお願いします。
発生している問題・エラーメッセージ
0時から24時のプルダウンメニューで初期表示を9時に設定できない
該当のソースコード
javascript
1/* 2 今日の日付データを変数todayに格納 3 */ 4 var optionLoop, this_day, this_month, this_year, today; 5 today = new Date(); 6 this_year = today.getFullYear(); 7 this_month = today.getMonth() + 1; 8 this_day = today.getDate(); 9 10 optionLoop = function (start, end, id, this_day) { 11 var i, opt; 12 13 opt = null; 14 for (i = start; i <= end; i++) { 15 if (i === this_day) { 16 opt += "<option value='" + i + "' selected>" + i + "</option>"; 17 } else { 18 opt += "<option value='" + i + "'>" + i + "</option>"; 19 } 20 } 21 return document.getElementById(id).innerHTML = opt; 22 23 }; 24 25 /* 26 ループ処理(表示id名、デフォルト数字) 27 */ 28 timeLoop = function (id, this_time) { 29 var hour, opt; 30 opt = null; 31 var minute = [':00', ':30']; 32 var count = 0; 33 for (var hour = 0; hour <= 24;) { 34 if (i === this_time) { 35 opt += "<option value='" + hour + "' selected>" + hour + "</option>"; 36 } else { 37 opt += "<option value='" + hour + "'>" + hour + "</option>"; 38 } 39 text.push(tagF + hour + minute[count] + tagE); 40 count++; 41 if (count == 2) { 42 count = 0; 43 hour++; 44 } 45 } 46 }
HTML
1<!-- 日付表示 --> 2 <script type="text/javascript"> 3 /* 4 関数設定(スタート数字、終了数字、表示id名、デフォルト数字) 5 */ 6 $(function() { 7 optionLoop(this_year - 5, this_year + 5, 'id_year', this_year); 8 optionLoop(1, 12, 'id_month', this_month); 9 optionLoop(1, 31, 'id_day', this_day); 10 }) 11 12 $(function() { 13 optionLoop(this_year - 5, this_year + 5, 'bar_year', this_year); 14 optionLoop(1, 12, 'bar_month', this_month); 15 optionLoop(1, 31, 'bar_day', this_day); 16 }) 17 </script> 18</head> 19 20 21<tr> 22<td>開始時間</td> 23 <td> 24 <div id="id_start"> 25 <select name="time" class="sel_time"> 26 <script type="text/javascript"> 27 var text = times(); 28 for (var i = 0; i < text.length; i++) { 29 document.write(text[i]); 30 } 31 </script> 32 </select> 33 </div> 34 </td> 35 36 </tr> 37 <tr> 38 <td>終了時間</td> 39 <td> 40 <select name="time" class="sel_time"> 41 <script type="text/javascript"> 42 var text = times(); 43 for (var i = 0; i < text.length; i++) { 44 document.write(text[i]); 45 } 46 </script> 47 </select> 48 </td> 49 </tr>
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/11/14 04:23
2018/11/14 05:15