2017-07-01 10 views
0

私はjquery datepickerを使用しています。月と年が必要です。入力フィールドをクリックすると、月と年のピッカーがうまくポップアップします。問題は、月または年を選択したときに、ページ上の他の場所をクリックしない限り、更新されたデータが入力フィールドに反映されないことです。jQuery月/年のピッカーが選択時の入力で月/年を表示しない

ザ・は私がここで間違ってやっている何ピッカー

$(function() { 
    $(".datepicker").datepicker({ 
     changeMonth: true, 
     changeYear: true, 
     yearRange: "-100:+0", 
     dateFormat: 'MM yy', 
     onClose: function (dateText, inst) { 
      $(this).datepicker('setDate', new Date(inst.selectedYear, inst.selectedMonth, 1)); 
     } 
    }); 
}); 

を表示していますどのようにでしょうか?任意の月または年をクリックするとすぐに、更新された選択を反映する入力フィールドが必要です。

+1

にonSelect使用の代わりにonSelectが動作しないonCloase – JYoThI

答えて

1

日付ピッカーは、新しい月および/または年に移動したときに呼び出され代わりにonClose

onChangeMonthYearの使用onChangeMonthYear。この関数は、選択された年、月(1〜12)、およびdatepickerインスタンスをパラメータとして受け取ります。関連する入力フィールドを参照します。

$(function() { 
    $(".datepicker").datepicker({ 
     changeMonth: true, 
     changeYear: true, 
     yearRange: "-100:+0", 
     dateFormat: 'MM yy', 
     onChangeMonthYear: function (year,month, inst) { 
      $(this).datepicker('setDate', new Date(inst.selectedYear, inst.selectedMonth, 1)); 
     } 
    }); 
}); 

$(function() { 
 
     $(".datepicker").datepicker({ 
 
      changeMonth: true, 
 
      changeYear: true, 
 
      yearRange: "-100:+0", 
 
      dateFormat: 'MM yy', 
 
      onChangeMonthYear: function (year,month, inst) { 
 
       $(this).datepicker('setDate', new Date(inst.selectedYear, inst.selectedMonth, 1)); console.log(inst.selectedYear,inst.selectedMonth); 
 
      } 
 
     }); 
 
    });
<input class="datepicker" type="text" /><br /> 
 
<script src="https://code.jquery.com/jquery-1.12.4.js"></script> 
 
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script> 
 
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> 
 

 
<!-- Latest compiled JavaScript --> 
 
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

+0

、私はフィールドの外にクリックしたときにOnCloseのは、少なくとも、選択したデータを表示しましたが、にonSelectが何 – Saadia

+0

が私の更新を試してみてくださいしません答え@Saadia – JYoThI

+0

ありがとうございました。 – Saadia

関連する問題