[英]How to validate start and end date in jquery datepicker without day.?
我有两个仅选择月份和年份的日期选择器。 我需要验证这两个日期选择器。 如果我从 onedatepicker (starDate) 中选择一个月份和年份,比如 2017 年 2 月和所有之前的日期(如 2017 年 1 月、2016 年 12 月、2016 年 11 月等等)应该在 seconddatepicker (endDate) 中禁用。 我已经设置了一个 minValue 但不起作用。
这是我的小提琴
<p>Start Date 1: <input type="text" id="startDate"></p>
<p>End Date 1: <input type="text" id="endDate"></p>
<script>
$("#startDate").datepicker({
changeMonth: true,
changeYear: true,
beforeShowDay: function (date) {
return [''];
},
showButtonPanel: true,
dateFormat: 'MM yy',
onClose: function (dateText, inst) {
var minValue = $(this).val();
jQuery(this).datepicker('setDate', new Date(inst.selectedYear, inst.selectedMonth, 1));
$("#endDate").datepicker({
changeMonth: true,
changeYear: true,
beforeShowDay: function (date) {
return [''];
},
showButtonPanel: true,
dateFormat: 'MM yy',
minValue:minValue,
onClose: function (dateText, inst) {
jQuery(this).datepicker('setDate', new Date(inst.selectedYear, inst.selectedMonth, 1));
},
});
},
});
<script>
谢谢。 :)
得到了我的答案。 :)
小提琴: https : //jsfiddle.net/n1gzbkru/2/
$("#startDate").datepicker({
changeMonth: true,
changeYear: true,
beforeShowDay: function (date) {
return [''];
},
showButtonPanel: true,
dateFormat: 'MM yy',
onClose: function (dateText,inst) {
$(this).datepicker('setDate', new Date(inst.selectedYear, inst.selectedMonth, 1));
var month = inst.selectedMonth;
console.log(month);
$("#endDate").datepicker({
changeMonth: true,
changeYear: true,
minDate:"+"+(month+1)+"m",
beforeShowDay: function (date) {
return [''];
},
showButtonPanel: true,
dateFormat: 'MM yy',
onClose: function (dateText,inst) {
jQuery(this).datepicker('setDate', new Date(inst.selectedYear, inst.selectedMonth, 1));
},
});
},
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.