仅显示月份和年份不适用于 jQuery-2.1.1

Display only month and year not working with jQuery-2.1.1

我的日期选择器与 jQuery-1.9.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,现在我的日期选择器不工作了。有人可以帮帮我吗?谢谢!

更新 谢谢“Pekka”的参考。但即使在添加了 jqueryui 文件之后......这就是我得到的:

而我正在寻找以下格式

有什么建议吗?再次感谢!!

给你,

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

DEMO

您也可以使用 startView 代替 viewmode 并设置选项..