1

我的datepicker與jQuery-1.9.1完美配合。僅顯示月份和年份不適用於jQuery-2.1.1

HTML:

<label> Select month & year: </label> 
<input name="month" class="month_year" placeholder="mm/yyyy"/> 

的jQuery:

$(function() { 
     $('.month_year').datepicker({ 
      changeMonth: true, 
      changeYear: true, 
      showButtonPanel: true, 
      dateFormat: 'MM yy', 
      onClose: function(dateText, inst) { 
       var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val(); 
       var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val(); 
       $(this).datepicker('setDate', new Date(year, month, 1)); 
      } 
     }).focus(function() { 
      $(".ui-datepicker-calendar").hide(); 
     }); 
    }); 

Here是該的jsfiddle。

但後來我們不得不開始使用jQuery-2.1.1,現在我的datepicker不工作。有人可以幫幫我嗎?謝謝!

更新 謝謝「佩卡」作爲參考。但即使添加了jQueryUI的文件後,...這是我得到:

enter image description here

而我要找的格式如下

enter image description here

什麼建議嗎?再次感謝你!!

+0

http://stackoverflow.com/questions/25784944/jquery-datepicker-calendar-does-not-appear檢查它 – guradio

+0

在小提琴中你還在使用'jquery-1.9'? –

+0

您正在尋找'bootstrap datepicker'? –

回答

3

在這裏你去,

$('.month_year').datepicker({ 
    format: 'MM yy', 
    viewMode: "months", //this 
    minViewMode: "months",//and this 
    //autoClose:true 
}); 

DEMO

您還可以使用startView instad的viewmode,並設置選項..

+0

任何時候..快樂編碼.. :) –

相關問題