【发布时间】:2015-03-17 12:17:52
【问题描述】:
我使用 jquery datepicker 作为月份选择器,它正在工作,但唯一的问题是,如果我从日历中选择一个月,那么它会在输入字段中显示该月份,但是当我再次单击该输入字段时它不会显示所选月份,但显示当前月份。
HTML
<label for="startDate">Date :</label>
<input name="startDate" id="startDate" class="date-picker" />
JS
$(function() {
$('.date-picker').datepicker( {
changeMonth: true,
changeYear: true,
showButtonPanel: true,
dateFormat: 'MM yy',
onClose: function(dateText, inst) {
function isDonePressed(){
return ($('#ui-datepicker-div').html().indexOf('ui-datepicker-close ui-state-default ui-priority-primary ui-corner-all ui-state-hover') > -1);
}
if (isDonePressed()){
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));
console.log('Done is pressed')
}
}
});
});
这是我的问题的小提琴。 http://jsfiddle.net/DBpJe/5103/
【问题讨论】:
-
是的,我检查了这个,但没有得到解决方案
-
这不适用于 dateFromat: "MM yy"
-
无法重现您的问题。你的小提琴适合我。真正的问题是什么?
-
选择十二月的月份然后按完成,再次点击输入框会显示你在十二月的地方行军。
标签: javascript jquery jquery-ui datepicker