这是我的jQuery日历代码
$(document).ready(function(){
$( "#fromDate" ).datepicker({
dateFormat: 'mm-dd-yy',
changeMonth:true,
changeYear:true,
showOn: "button",
buttonImage: "../../images/calendar.gif",
buttonImageOnly: true,
maxDate: '0',
onSelect: function(dateText, inst)
{$("#toDate").val('');
$("#toDate").datepicker("option", "minDate", dateText);
}
});
$( "#toDate" ).datepicker({
dateFormat: 'mm-dd-yy',
changeMonth:true,
changeYear:true,
showOn: "button",
maxDate: '0',
buttonImage: "../../images/calendar.gif",
buttonImageOnly: true
});
});
</script>
我是这样的,以便#toDate
中允许的天数不应超过#fromDate + 30
我该怎么做?
请注意,两个日历已经不允许选择日期超过当天!
答案 0 :(得分:0)
datepicker具有属性minDate和maxDate。所以你可以用所需的日期设置这些属性。下面是一个样本,
var currentDate= new Date();
var maxdate = new Date(currentDate);
maxdate.setDate(currentDate.getDate() + 30);
$("#toDate").datepicker({
changeMonth: true,
changeYear: true, minDate:
currentDate, maxDate:maxdate
}).datepicker('setDate',currentDate);
参考:http://jsfiddle.net/2y67W/,Setting max date jquery datepicker