<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/base/jquery-ui.css" type="text/css" media="all"> <label for="from">From</label> <input type="text" id="fDate" name="from"/> <label for="to">to</label> <input type="text" id="toDate" name="to"/>
var dateToday = new Date(); var dates = $("#fDate, #toDate").datepicker({ defaultDate: "+1w", changeMonth: true, numberOfMonths: 3, minDate: dateToday, onSelect: function(selectedDate) { var option = this.id == "fDate" ? "minDate" : "maxDate", instance = $(this).data("datepicker"), date = $.datepicker.parseDate(instance.settings.dateFormat || $.datepicker._defaults.dateFormat, selectedDate, instance.settings); dates.not(this).datepicker("option", option, date); } });
执行效果:to的起始日期会随着from选中的日期变化
//如果想要控制toDate的时间范围 var newDate = new Date(); newDate.setDate(newDate.getDate() + day); $('#toDate').datepickTW("option", "maxDate", newDate);
目前博客园不能执行js,因此无法看到实时的效果