我有两个日期选择器“startDate”和“targetDate”。我想将“targetDate”的minDate设置为“startDate”的值。以下 代码不起作用。即,未设置“targetDate”的 minDate。
$("#startDate").datepicker({
changeMonth : true,
changeYear : true,
dateFormat : "dd-M-yy",
minDate : 0,
showMonthAfterYear : true,
onClose : function() {
$(this).toggleClass('ui-state-focus');
}
});
$("#targetDate").datepicker({
changeMonth : true,
changeYear : true,
dateFormat : "dd-M-yy",
minDate : new Date($("#startDate").val()),
showMonthAfterYear : true,
onClose : function() {
$(this).toggleClass('ui-state-focus');
}
});
最佳答案
您需要在onSelect中设置targetDate的最小日期startDate的事件
Called when the datepicker is selected. The function receives the selected date as text and the datepicker instance as parameters. this refers to the associated input field.
使用
$('#startDate').datepicker({
onSelect: function(selectedDate) {
$('#targetDate').datepicker('option', 'minDate', selectedDate);
}
});
关于javascript - jQuery 日期选择器 minDate 未设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25377817/