Javascript jquery ui datepicker选项dateformat未正确响应
我想使用jQueryUIDatePicker来选择月份和年份。在网站中搜索后,我创建了此功能:Javascript jquery ui datepicker选项dateformat未正确响应,javascript,jquery,jquery-ui,datepicker,jquery-ui-datepicker,Javascript,Jquery,Jquery Ui,Datepicker,Jquery Ui Datepicker,我想使用jQueryUIDatePicker来选择月份和年份。在网站中搜索后,我创建了此功能: $(".datepickerSchedule").datepicker({ showOn: "both", changeMonth: true, changeYear: true, dateFormat: "yy-mm", minDate: new Date(taskStartDat
$(".datepickerSchedule").datepicker({
showOn: "both",
changeMonth: true,
changeYear: true,
dateFormat: "yy-mm",
minDate: new Date(taskStartDate),
showButtonPanel: true,
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));
}
}
}).focus(function(){
$(".ui-datepicker-calendar").hide();
});
所以在焦点上,我隐藏了日历,只有当我按下Done时,所选月份的第一个日期才被设置为Datepicker
选择月份后,格式正确显示为mm yy
但在我的屏幕中,我从DB加载了ThymileAF日期,我遇到了问题,因为dateformat不适用,我得到的日期为yy-mm-dd。我用来设置输入的模型对象有一个日期变量(尽管它使我相信它有解析问题,因为输入类型是文本)
此外,当我将格式设置为“mm-yy”时,datepicker不识别字段中已经存在的日期,并且在当月打开,因此,例如,如果我有2017-11-01,datepicker将打开到2019年3月(如果dateformat为“yy-mm-dd”,则不会发生此情况,但如果dateformat为“mm-yy”或“yy-mm”,则会发生此情况)
最后一部分如何排除选择一年的月份?我知道具体日期,但如果从当天的阅读中排除整个月份,我能做什么