尝试在此代码中设置 todate 4 天 + 的 fromdate 选定值,但无法使其正常工作。我想要的是当一个人选择第一个日历日期时,我希望第二个 minDate 比选择的第一个日期的值晚 4 天。
<?php
// has all script and css includes
include('includes/header.php');
?>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
<div class="container">
<div class="row">
<div class="span3"></div>
<div class="span9">
<input class='fromdate' id='fromdate' />
<input class='todate' id='todate' />
<input class='calculated' />
<!-- <input class='minim' /> -->
</div>
</div>
</div>
<script>
$('.fromdate').datepicker({
dateFormat: 'mm-dd-yy',
minDate:(+4)
});
$('.todate').datepicker({
dateFormat: 'mm-dd-yy'
});
$('.fromdate').datepicker().bind("change", function () {
var minValue = $(this).val();
minValue = $.datepicker.parseDate("mm-dd-yy", minValue);
$('.todate').datepicker("option", "minDate", minValue);
calculate();
});
$('.todate').datepicker().bind("change", function () {
var maxValue = $(this).val();
maxValue = $.datepicker.parseDate("mm-dd-yy", maxValue);
$('.fromdate').datepicker("option", "maxDate", maxValue);
calculate();
});
function calculate() {
var d1 = $('.fromdate').datepicker('getDate');
var d2 = $('.todate').datepicker('getDate');
var diff = 1;
if (d1 && d2) {
diff = diff + Math.floor((d2.getTime() - d1.getTime()) / 86400000); // ms per day
}
$('.calculated').val(diff);
$('.minim').val(d1)
}
</script>