我从这里开始约会。我想将maxDate设置为3个月取决于从日期选择。如果用户从日期01-01-2014中选择,#maxDate应该是基于起始日期的下一个3个月,如(01-04-2014)。
$(function () {
$("#from").datepicker({
minDate: "dateToday",
changeMonth: true,
dateFormat: 'dd-mm-yy',
onClose: function (selectedDate) {
$("#to").datepicker("option", "minDate", selectedDate);
}
});
$("#to").datepicker({
minDate: "dateToday",
changeMonth: true,
dateFormat: 'dd-mm-yy',
maxDate: selectedDate + "+3M", //I want to set condition like this
onClose: function (selectedDate) {
$("#from").datepicker("option", "maxDate", selectedDate);
}
});
});
给我一些解决问题的建议
答案 0 :(得分:13)
$(function () {
$("#from").datepicker({
minDate: "dateToday",
changeMonth: true,
dateFormat: 'dd-mm-yy',
onClose: function (selectedDate, instance) {
if (selectedDate != '') { //added this to fix the issue
$("#to").datepicker("option", "minDate", selectedDate);
var date = $.datepicker.parseDate(instance.settings.dateFormat, selectedDate, instance.settings);
date.setMonth(date.getMonth() + 3);
console.log(selectedDate, date);
$("#to").datepicker("option", "minDate", selectedDate);
$("#to").datepicker("option", "maxDate", date);
}
}
});
$("#to").datepicker({
minDate: "dateToday",
changeMonth: true,
dateFormat: 'dd-mm-yy',
onClose: function (selectedDate) {
$("#from").datepicker("option", "maxDate", selectedDate);
}
});
});
答案 1 :(得分:3)
$(function() {
$( "#datepicker" ).datepicker({
numberOfMonths: 3,
showButtonPanel: true
});
});
$("#startDate").datepicker({
minDate: 0,
onSelect: function(selected) {
var date = new Date(selected);
date.setMonth(date.getMonth()+3);
$("#endDate").datepicker("option","maxDate", date);
}
});
这是你的男人......干杯......