我正在四处寻找约会选择器,以进行预订。
下面的代码几乎完全按照我想要的方式工作。
问题是:我不希望“去”日期选择器在未来的一天之内允许任何事情。
例如,如果“发件人”是13/09/25,我希望“发件人”至少是26/09/13。
我需要进行哪些更改才能按照自己的方式进行操作?
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<link rel="stylesheet" href="http://jqueryui.com/datepicker//resources/demos/style.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script>
$(function() {
$( "#from" ).datepicker({
defaultDate: "+0w",
changeMonth: true,
numberOfMonths: 1,
minDate: -0,
onClose: function( selectedDate ) {
$( "#to" ).datepicker( "option", "minDate" , selectedDate );
}
});
$( "#to" ).datepicker({
defaultDate: "+0w",
changeMonth: true,
numberOfMonths: 1,
onClose: function( selectedDate ) {
$( "#from" ).datepicker( "option", selectedDate );
}
});
});
</script>
<form action="?q=Reservation" method="post">
<label for="from">From</label>
<input type="text" id="from" name="from" />
<label for="to">to</label>
<input type="text" id="to" name="to" />
First name: <input type="text" name="FirstName" value="Mickey"><br>
Last name: <input type="text" name="LastName" value="Mouse"><br>
<input type="submit" value="Submit">
</form>
您可以执行以下操作:
$("#from").datepicker({
defaultDate: "+0w",
changeMonth: true,
numberOfMonths: 1,
minDate: -0,
onClose: function (selectedDate) {
var date2 = $('#from').datepicker('getDate');
date2.setDate(date2.getDate() + 1);
$("#to").datepicker("option", "minDate", date2);
}
});
因此,您可以从日期获取当前日期,并使用为其添加一天setDate
,然后根据需要设置该minDate
选项。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句