【发布时间】:2014-06-10 06:19:43
【问题描述】:
我正在使用第 3 方 jQuery UI Timepicker,可以在此 git 存储库中找到:
jQuery UI Timepicker
我已经实现了一个日期时间范围选择器,只需让两个datetimepicker 输入元素将它们选择的日期作为另一个字段的最小或最大日期时间传递。它可以工作并且设置了最小和最大日期时间,但是当我删除一个字段时,它不会重置其他字段的最小/最大时间。
例如,假设我将from 字段设置为4/23 5:00p。我的to 字段不能设置早于4/23 5:00p。当我从from 中删除值时,它应该将to 的最小时间重置回12:00a,因为不再设置from,但它仍保持在5:00p,即使minDateTime 函数具有已设置为null。
第一次设置后如何才能真正恢复默认设置?
var fromDatepickerPointer = fromValueFieldPointer.inputElement;
var toDatepickerPointer = toValueFieldPointer.inputElement;
function fromOnCloseFunction(selectedDateTime, inst) {
if(fromDatepickerPointer.val() != '') {
var minTime = new Date($(this).datetimepicker('getDate').getTime());
console.log("minTime: " + minTime);
console.log("from SelectedDateTime: " + selectedDateTime);
toDatepickerPointer.datetimepicker('option', 'minDateTime', minTime);
toDatepickerPointer.datetimepicker('option', 'minDate', minTime);
} else {
console.log("from should be set to null but isn't");
toDatepickerPointer.datetimepicker('option', 'minDateTime', null);
toDatepickerPointer.datetimepicker('option', 'minDate', null);
}
}
fromDatepickerPointer.datetimepicker('option', 'onClose', fromOnCloseFunction);
function toOnCloseFunction(selectedDateTime, inst) {
if(toDatepickerPointer.val() != '') {
var maxTime = new Date($(this).datetimepicker('getDate').getTime());
console.log("maxTime: " + maxTime);
console.log("to SelectedDateTime: " + selectedDateTime);
fromDatepickerPointer.datetimepicker('option', 'maxDate', maxTime);
fromDatepickerPointer.datetimepicker('option', 'maxDateTime', maxTime);
} else {
console.log("to should be set to null but isn't");
fromDatepickerPointer.datetimepicker('option', 'maxDate', null);
fromDatepickerPointer.datetimepicker('option', 'maxDateTime', null);
}
}
toDatepickerPointer.datetimepicker('option', 'onClose', toOnCloseFunction);
老实说,我觉得这是插件本身的问题,而不是我的代码,但我想你可以判断这一点。
【问题讨论】:
标签: javascript jquery jquery-ui datetime datetimepicker