下記の参考サイトをもとにセレクトボックスを使って<label>内のデータの表示させるスプリクトをつているのですが、デフォルト時に<option>の最初の内容(ココでは<label id="label1" for="13" class="13">)を表示させたいですが、どうすればいいのかわかりません。
ちなみに、<select>と<label>の値はデータベースから値をと出しますので内容が変更されます。
どうかよろしくお願いします。
javascript
1$(function() { 2 //This hides all initial textboxes 3 $('label').hide(); 4 $('#ons').change(function() { 5 //This saves some time by caching the jquery value 6 var val = $(this).val(); 7 //this hides any boxes that the previous selection might have left open 8 $('label').hide(); 9 //This just opens the ones we want based off the selection 10 $('.' + val).show(); 11 }); 12 //I'm not really sure why these are here 13 $("input") 14 .focus(function () { 15 $(this).next("span").fadeIn(1000); 16 }) 17 .blur(function () { 18 $(this).next("span").fadeOut(1000); 19 }); 20});
html
1 <form> 2 <select id="ons"> 3 <option value="13">第13号 2016 autumn</option> 4 <option value="12">第12号 2016 spring</option> 5 <option value="11">第11号 2016 winter</option> 6 </select> 7 </form> 8 <label id="label1" for="13" class="13"> 9 <div class="image paper"><a href="url" target="_blank"><img src="写真" width="780" alt=""/></a></div> 10 <div class="btn trans"><a href="url"><span>PDFダウンロード</span></a></div> 11 </label> 12 <label id="label2" for="12" class="12"> 13 <div class="image paper"><a href="url" target="_blank"><img src="写真" width="780" alt=""/></a></div> 14 <div class="btn trans"><a href="url"><span>PDFダウンロード</span></a></div> 15 </label> 16 <label id="label3" for="11" class="11"> 17 <div class="image paper"><a href="url" target="_blank"><img src="写真" width="780" alt=""/></a></div> 18 <div class="btn trans"><a href="url"><span>PDFダウンロード</span></a></div> 19 </label>
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/12/15 08:51