使用jQuery UI的datepicker日期范围,如何自定义默认功能,以便在选择开始日期时结束日期的最小日期与开始日期不同,但开始日期为+ 1天。
我知道我可以用开始日期getDate()
上调用的setDate()
和val()
函数替换'selectedDate',但我想知道是否支持预期的功能由datepicker。像selectedDate +1 day
这样的东西,但显然我已经尝试过了,但这不起作用。
Bellow是我目前使用的代码,它将minDate
#to
的选项设置为#from
<input type="text" id="from" name="from">
<input type="text" id="to" name="to">
<script>
$(function() {
$( "#from" ).datepicker({
onClose: function( selectedDate ) {
$( "#to" ).datepicker( "option", "minDate", selectedDate );
//how to change this so that the minDate is selectedDate + 1 day?
}
});
$( "#to" ).datepicker({
onClose: function( selectedDate ) {
$( "#from" ).datepicker( "option", "maxDate", selectedDate );
}
});
});
</script>
答案 0 :(得分:0)
你可以用这个
var actualDate = new Date(selectedDate);
var newDate = new Date(actualDate.getFullYear(), actualDate.getMonth(), actualDate.getDate()+1);
$(function() {
$( "#from" ).datepicker({
onClose: function( selectedDate ) {
//$( "#to" ).datepicker( "option", "minDate", selectedDate );
//how to change this so that the minDate is selectedDate + 1 day?
var actualDate = new Date(selectedDate);
var newDate = new Date(actualDate.getFullYear(), actualDate.getMonth(), actualDate.getDate()+1);
$("#to").datepicker("option","minDate", newDate)
},
});
$( "#to" ).datepicker({
onClose: function( selectedDate ) {
$( "#from" ).datepicker( "option", "maxDate", selectedDate );
}
});
});
&#13;
<link href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.1/jquery-ui.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.1/jquery.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.1/jquery-ui.js"></script>
<input type="text" id="from" name="from">
<input type="text" id="to" name="to">
&#13;