假设您使用的是 jQuery UI 的日期选择器,我认为您正在寻找日期范围。你会有这样的标记:
<label for="from">From</label>
<input type="text" id="from" name="from" />
<label for="to">to</label>
<input type="text" id="to" name="to" />
然后,在 JS 中,
$(function() {
$( "#from" ).datepicker({
//not needed
defaultDate: "+1w",
//to show the month dropdown
changeMonth: true,
//the number of months to be shown when input is focussed
numberOfMonths: 1,
//**Important!**
onClose: function( selectedDate ) {
//dynamically set min-date of second datepicker to selected date in the first datepicker
$( "#to" ).datepicker( "option", "minDate", selectedDate );
}
});
$( "#to" ).datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 1,
onClose: function( selectedDate ) {
//dynamically set max-date property of #from text box
$( "#from" ).datepicker( "option", "maxDate", selectedDate );
}
});
});
文档:http: //jqueryui.com/datepicker/#date-range