我正在尝试显示一个仅显示月份+年份菜单的日期选择器,就像这个 Q' 中那样jquery 日期选择器仅显示月份年份 https://stackoverflow.com/questions/2208480/jquery-date-picker-to-show-month-year-only,这不是问题,但我遇到以下问题
我希望输入文本加载日期的字符串值,例如 01/2011,并且我希望在 focusin 事件中,日期选择器将加载显示的日期,我的意思是我希望它已经在 2011 年和 01 月打开选定的,
但由于某种原因,当我单击文本输入时,原始日期“01/2011”更改为“01/01/2011”
这是我的代码
$(document).delegate("#timeSpanFrom, #timeSpanTo", "focusin", function() {
var $this = $(this);
var inputDate = $.datepicker.parseDate('dd/mm/yy', "01/"+$this.val());
if (!$this.data('datepicker_enabled')) {
$this.datepicker({
changeMonth : true,
changeYear : true,
showButtonPanel : true,
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));
$(".ui-datepicker-calendar").hide();
}
});
$this.datepicker({ dateFormat: 'mm/yy' });
$this.datepicker('setDate', inputDate);
$this.data('datepicker_enabled',true);
}
});
$(document).delegate("#timeSpanFrom, #timeSpanTo", "focus", function() {
$(".ui-datepicker-calendar").hide();
});
在此先感谢