2016-04-12 13 views
1

これは実際の内容です。以下のコードでは、UIで2回のドロップダウンに値を追加しました。代わりに、「4月」Jqueryの値を設定し、同じ値の2倍を追加しました

if ($('#dk_container_selectToYear .dk_options li.dk_option_current a').text() == 2016) { 
      var currentdate = new Date(); 
      var month = currentdate.getMonth(); 
      var monthname = monthLookup[currentdate.getMonth()]; 
      month = month + 3; 
      while (month <= 13) { 
       $('#dk_container_selectToMonth .dk_options li:nth-child(' + month + ')').css({ "display": 'none' }); 
       var listvalue = $('#dk_container_selectToMonth .dk_options li:nth-child(' + month + ')').text(); 

       if ($('#dk_container_selectToMonth .dk_options li.dk_option_current a').text() == listvalue) { 
        $('#selectToMonth').dropkick('reset'); 
        $('#selectToMonth').dropkick('setValue', monthname); 
       } 

       month++; 
      } 
     } 


$('#selectToMonth').dropkick('setValue', monthname); 

の「AprilAprilは」それはそれを避けるために、他のオプションを持っているので、これではありません!!

+0

monthLookupはどのように見えるのですか? – Coss

+0

設定した後に 'monthname'ログをコンソールに表示した場合、何が表示されますか? –

答えて

2

..事前に

感謝をドロップダウン値を表示しますあなたの質問には解決策がありますが、解決策が見つかるまでハックするだけです。 ただ、このように...文字列の半分をつかむ:

var monthname = 'AprilApril'; 
var month = monthname; 
console.log(month.substr(0, (month.length/2))); // April 
console.log(month) // AprilApril 

はコーディングをお楽しみください!

関連する問題