我正在使用 jQuery 日期选择器。我能够计算两个选定日期之间的天数,但我需要能够选择一个日期范围(选择'fromdate'成为'todate'的'minim',选择'todate'成为'maxim'从日期')。我正在使用这段代码:
<script type="text/javascript">
$(document).ready(function () {
var selector = function (dateStr) {
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)
}
$('.fromdate').datepicker({
dateFormat : 'yy-mm-dd',
changeMonth: true,
changeYear: true,
minDate: 'minim'
});
$('.todate').datepicker({
dateFormat : 'yy-mm-dd',
changeMonth: true,
changeYear: true,
minDate: 'fromdate'
});
$('.fromdate,.todate').change(selector)
});
</script>
谢谢!