如果您查看,开始日期的选定值是“2016 年 12 月”,但当我单击它时,它会显示当前的月份和年份。它应该显示所选值(2016 年 12 月)。 知道如何解决吗?
下面是开始日期日期选择器的代码:
$('#startDateEdEdit').datepicker({
changeMonth: true,
changeYear: true,
showButtonPanel: true,
dateFormat: 'MM yy',
setDate: startDateEd,
yearRange: `1920:${todayYear+10}`,
onClose: function(dateText, inst) {
startDateEdEdit = new Date(inst.selectedYear, inst.selectedMonth, 1);
$(this).datepicker('setDate', new Date(inst.selectedYear, inst.selectedMonth, 1));
if(endDateEdEdit < startDateEdEdit){
$('#endDateEdEdit').datepicker('setDate',null);
}
else {
var duration = $('#endDateEdEdit').datepicker('getDate')?durationCalculator(startDateEdEdit, endDateEdEdit):null;
document.getElementById('durationEdit').value = duration.duration;
document.getElementById('eduEdit-duration').value = duration.years;
}
}
});
最佳答案
日期选择器日期格式字段似乎存在一些问题。您可以做的是将 dateFormat: 'MM yy'
替换为 dateFormat: 'dd MM, yy'
这样可以吗?
关于javascript - Jquery 日期选择器下拉列表显示当前日期而不是所选日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47884071/