【发布时间】:2019-06-13 09:40:45
【问题描述】:
我有两个日期选择器。第一个日期选择器是开始日期,第二个日期选择器是结束日期。
我的年份范围是
2018-2019 (Last date is 31-03-2019)
2019-2020 (My start date is 01-04-2019 and the end date is 31-03-2020)
2020-2021 (My start date is 01-04-2020 and the end date is 31-03-2021)
//and so on
现在按照当年,我们在2018-2019的范围内。
所以我的结束日期是 31-03-2019。
如何显示结束日期 31-03- 年(取决于 start_date)?
我应该需要一些 jquery 或 PHP 来处理这个吗?
$(function() {
var year = (new Date).getFullYear();
$(".start_date").datepicker({
showOn: "button",
buttonImage: "http://jqueryui.com/resources/demos/datepicker/images/calendar.gif",
buttonImageOnly: true,
buttonText: "Select date",
dateFormat: "dd-mm-yy",
changeMonth: true,
changeYear: true,
minDate: 0,
//maxDate : "+1Y",
maxDate: new Date(year, 03, 31),
// maxDate: "+3m"
showAnim: "clip",
numberOfMonths: 1
});
$(".end_date").datepicker({
showOn: "button",
buttonImage: "http://jqueryui.com/resources/demos/datepicker/images/calendar.gif",
buttonImageOnly: true,
buttonText: "Select date",
dateFormat: "dd-mm-yy",
changeMonth: true,
changeYear: true,
minDate: 0,
//maxDate : "+1Y",
maxDate: new Date(year, 03, 31),
showAnim: "clip"
//numberOfMonths: 2
});
});
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<div class="form-group">
<label>Start Date</label>
<input type="text" name="start_date" placeholder="Start Date" id="start_date" class="start_date form-control">
</div>
<div class="form-group">
<label>End Date</label>
<input type="text" name="end_date" id="end_date" placeholder="End Date" class="end_date form-control">
</div>
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.3.1.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
你能帮我解决这个问题吗?
【问题讨论】:
-
为什么不
maxDate: new Date(year + 1, 03, 31)
标签: php jquery jquery-ui datepicker