$('#stpartdates').datepicker({
changeMonth: true,
changeYear: true,
onSelect: function(date) {
var date2 = $('#stpartdates').datepicker('getDate');
date2.setDate(date2.getDate() + 365);
$('#etpartdates').datepicker('setDate', date2);
$('#etpartdates').datepicker('option', 'minDate', date2);
}
});
$('#etpartdates').datepicker({
changeMonth: true,
changeYear: true,
minDate: $('#stpartdates').val(),
onSelect: function() {
// $("#ui-datepicker-div").hide();
}
});
stpartdates
是一个开始日期,etpartdates
是结束日期,
如果用户选择04-08-2014
我想显示结束日期的年份范围仅为2015
我的意思是
start date year + 1 = end date yearrange
答案 0 :(得分:0)
试试这个
var date = $(this).datepicker('getDate'),
year = date.getFullYear() + 1;
$("#etpartdates").datepicker("option", "minDate", "01/01/" + year);
而不是
$('#etpartdates').datepicker('setDate', date2);
答案 1 :(得分:0)
尝试以下代码
$("#stpartdates,#etpartdates").datepicker({
changeMonth: true,
changeYear: true,
onSelect: function (dateText, obj) {
var MinDate = new Date(dateText);
var MaxDate = new Date(dateText);
var newDateRangeMax = new Date(MinDate.getFullYear()+1,MinDate.getMonth(),MinDate.getDate());
var newDateRangeMin = new Date(MaxDate.getFullYear()-1, MaxDate.getMonth(),MaxDate.getDate());
if ($(this).attr("id") == "stpartdates") {
$("#etpartdates").datepicker("option", "minDate", newDateRangeMin );
}
else{
$("#stpartdates").datepicker("option", "maxDate", newDateRangeMax)
}
});