jQuery月/年选择器在进行选择时未在输入中显示月/年

jQuery月/年选择器在进行选择时未在输入中显示月/年,jquery,datepicker,jquery-ui-datepicker,Jquery,Datepicker,Jquery Ui Datepicker,我正在使用jQueryDatePicker,我只需要一个月和一年。当我点击输入字段时,月份和年份选择器就会弹出。问题是,当我选择任何月份或年份时,更新的数据不会反映在输入字段中,除非我单击页面上的其他位置 下面是我显示选择器的方式 $(function () { $(".datepicker").datepicker({ changeMonth: true, changeYear: true, yearRange: "-100:+0",

我正在使用jQueryDatePicker,我只需要一个月和一年。当我点击输入字段时,月份和年份选择器就会弹出。问题是,当我选择任何月份或年份时,更新的数据不会反映在输入字段中,除非我单击页面上的其他位置

下面是我显示选择器的方式

$(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));
        }
    });
});

我做错了什么?只要单击任何月份或年份,我就需要输入字段来反映更新的选择。

使用
onChangeMonthYear
而不是
onClose

onChangeMonthYear
在日期选择器移动到新的月份和/或年份时调用。函数接收所选的年、月(1-12)和日期选择器实例作为参数。这是指关联的输入字段

$(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));
        }
    });
});
$(函数(){
$(“.datepicker”).datepicker({
变化月:对,
变化年:是的,
年份范围:“-100:+0”,
日期格式:“MM yy”,
onChangeMonthYear:功能(年、月、月){
$(此).datepicker('setDate',新日期(inst.selectedYear,inst.selectedMonth,1));console.log(inst.selectedYear,inst.selectedMonth);
}
});
});


使用onSelect而不是onClose onSelect不起作用,当我在字段外单击时onClose至少显示了所选数据,但onSelect不做任何事情感谢您的帮助。很高兴帮助您@Saadia