javascript - jQuery Datepicker onClose 上的 SetDate 不会改变值
问题描述
我有一张桌子,每一行都有一个日期选择器。Datepickers 只选择月份,并且在关闭时我设置了该月的第一天,除非这一天在 minDate 之前,所以我想在那里设置 minDate。
SetDate 函数不起作用。我的日志告诉我正确设置了正确的日期,但是当我在 setDate 中传递它时,结果不会改变,并且它以某种方式堆叠到本月的第一天。我错过了什么?
function initDatepickerSchedule(){
$(".datepickerSchedule").each(function(){
$(this).datepicker({
showOn: "both",
changeMonth: true,
changeYear: true,
dateFormat: "yy-mm-dd",
minDate: scheduleTaskMinDate(),
maxDate: scheduleTaskMaxDate($(this).closest("tr").find(".ScheduledTaskQtyInput").val(),$(this).closest("tr").find(".ScheduledTaskCompletedQtyInput").val()),
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();
var properDate=new Date(year, month, 1);
var minDate=$(this).datepicker("option","minDate");
console.log(properDate);// 2019-12-1
console.log(minDate);//2019-12-2
console.log(properDate<minDate);// true
if(properDate<minDate){
properDate=minDate;
}
console.log("before set");
console.log(properDate===minDate);//true
console.log(properDate);//2019-12-2
$(this).datepicker("setDate",properDate);
console.log($(this).datepicker("getDate"));//2019-12-1
var coNo=$(this).closest("tr").find(".changeOrderNoInput").val();
$(this).closest("tr").find(".ScheduledTaskVersion").val(studyTaskScheduleVersion($(this).datepicker("getDate"),coNo));
$("#SubmitScheduleDistButton").prop('disabled', true).prop('title',"Validate without Errors to Unlock");
}
}
}).focus(function(){
$(".ui-datepicker-calendar").hide();
$(this).attr("autocomplete","off");
});
});
}
解决方案
似乎 max Date 真的很重要。在这种特定情况下,我应该在 maxDate 的同一个月内有一个日期,但由于某种原因(我不记得并检查了程序其他部分的可能影响,但我找不到任何问题)我返回了第一个日期本月的。
所以这没有显示在日期选择器案例日历上,所以我不知道。这就是它覆盖 maxDate 的设置函数原因的方式。
推荐阅读
- android - Benchmarking connection time interval in Android across different phones
- file - Fortran 程序的输入文件,包含“&PROBIN”
- r - r - 如何在不丢失数据的情况下取消 for 循环
- javascript - Web 性能:循环通过相同的 4 个 img src 发出太多请求
- machine-learning - 是否有 exp(-log loss) 作为评估指标的名称?
- phantomjs - 使用小袋鼠的 execute_script 运行 javascript 函数不起作用
- java-8 - 具有列表的可比类
场地 - java - Firestore 分页
- r - R - 通过多个列值匹配表中的行
- java - 日期格式 - Z 之后的数字(祖鲁时间)