我想设置第二个datepicket =第一个Datepicker + 1yr。并且还要选择第二个日期选择器直到选择第一个日期选择器?
我正在尝试这个
$("#BeginDate").datepicker({
changeMonth: true,
changeYear: true,
yearRange: '1900:2040',
showOn: "button",
buttonImageOnly: true,
beforeShow: function () {
$('#ui-datepicker-div').css('z-index', 9999);
},
onSelect: function(dateText, inst){
$("#EndDate").datepicker("option", "minDate",
$("#BeginDate").datepicker("getDate") +"1yr" **"{her we need set date}"**);
},
答案 0 :(得分:1)
您可以使用setFullYear
对象的Date
方法:
$("#BeginDate").datepicker({
changeMonth: true,
changeYear: true,
yearRange: '1900:2040',
showOn: "button",
buttonImageOnly: true,
beforeShow: function () {
$('#ui-datepicker-div').css('z-index', 9999);
},
onSelect: function(dateText, inst) {
var d = new Date($("#BeginDate").datepicker("getDate"));
d.setFullYear(d.getFullYear() + 1);
$("#EndDate").datepicker("option", "minDate", d);
}
});
$("#EndDate").datepicker()
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<p>Begin: <input type="text" id="BeginDate"></p>
<p>End: <input type="text" id="EndDate"></p>