2016-03-30 5 views
5

現在のドロップダウン値がの値リスト変数で使用可能な値を指している場合は、ドロップダウン選択値を最初の値に変更する必要があります。条件を満たしながらドロップダウン値を最初の値にリセット

$("#dk_container_selectForMonth").val($("#dk_container_selectForMonth li:first").val()); 

をしかし、それは動作しません:

if (selectedForYear() == 2016) { 
     var d = new Date(); 
     var month = d.getMonth(); 
     month = month + 3; 
     while (month <= 13) { 
      $('#dk_container_selectForMonth .dk_options li:nth-child(' + month + ')').css({ "display": 'none' }); 
      var listvalues = $('#dk_container_selectForMonth .dk_options li:nth-child(' + month + ')').text(); 
      if ($('#dk_container_selectForMonth .dk_options li.dk_option_current a').text() == listvalues) 
      { 

       $("#dk_container_selectForMonth").val($("#dk_container_selectForMonth li:first").val()); 

       } 
      month++; 
     } 
    } 

私はこれを試してみました。ここで

はHTMLです:

<div class="flexContainer mediumGutter"> 

    <div class="flexContent"> 
     <select data-bind="options: month, optionsCaption: 'Month', value: selectedForMonth" id="selectForMonth" tabindex="8" style="width: 130px"> 
      <option>month</option> 
     </select> 
    </div> 
    <div class="flexContent"> 
     <select data-bind="options: year, optionsCaption: 'Year', value: selectedForYear" id="selectForYear" tabindex="9" style="width: 130px"> 
      <option>year</option> 
     </select> 
    </div> 

はこれを行う方法はありますか?

+0

「HTML」を追加して、動作するスニペットを作成できるようにしてください。ここで紹介したものをデバッグするのは難しいです。 – sabithpocker

+0

@sabithpocker追加されたHTMLコンテンツを見つけてください – Kamal

答えて

2

申し訳ありませんが私の質問に答える。答えは誰かに役立つかもしれません。

jquery dropkick()メソッドを使用してドロップダウンをリフレッシュすると、ドロップダウンがリフレッシュされ、最初の値が割り当てられます。

$('#selectForMonth').dropkick('refresh'); 
+0

カスタムの選択プラグインを使用していますか? – NiZa

関連する問題