在datepicker中重设日期

问题描述:

我有一些在check in和check out日期使用的datepicker。我想限制每年12月31日之前的入住日期,并且不能在明年1月1日前显示。在退房日期,它只在明年1月1日显示。例如,我可以在2016年12月31日办理入住手续,但我可以在2017年1月1日前退房,但不能在2017年1月2日。在datepicker中重设日期

我试过这样的代码但不工作。

<!DOCTYPE html> 
<html> 
<head> 
    <title></title> 

    <link href="bootstrap.css" rel="stylesheet"> 
    <script src="https://code.jquery.com/jquery-1.10.2.js"></script> 
    <script src="bootstrap.js"></script> 
</head> 
<body> 

<p>Check In : <input type="text" id="datepicker-13"></p><br> 
<p>Check Out : <input type="text" id="datepicker-14"> 

</body> 

<script> 
    $(document).ready(function() { 
     var today = new Date(); 
     var lastDate = new Date(today.getFullYear(), 11, 31); 
     $('#datepicker-13').datepicker({ 
      maxDate: lastDate 
     }); 
    }); 

    $(document).ready(function() { 
     var today = new Date(); 
     var lastDate = new Date(today.getFullYear(), 11, 32); 
     $('#datepicker-14').datepicker({ 
      maxDate: lastDate 
     }); 
    }); 
</script> 
</html> 

谢谢。

+1

您是否阅读过文档,特别是关于'minDate'和'maxDate'设置的部分 – adeneo

+0

是的,我读过,但我不明白。 @adeneo – Nicholas

+0

你使用jQuery datepicker吗? – Ronald

您可以使用datepicker UI的maxDate。

在登记入住:

$(document).ready(function() { 
    var today = new Date(); 
    var lastDate = new Date(today.getFullYear(), 11, 31); 
    $('#check-in').datepicker({ 
     maxDate: lastDate 
    }); 
}); 

这将限制直至当年12月31日。

对于退房:

$(document).ready(function() { 
    var today = new Date(); 
    var lastDate = new Date(today.getFullYear(), 11, 32); 
    $('#check-out').datepicker({ 
     maxDate: lastDate 
    }); 
}); 

这将限制直至明年1月1日。