我一直在尝试实施一些额外的代码,以便在我的日期范围选择器中禁用一系列日期,从我的研究中我认为我需要使用beforeShowDay
,日期为{{1如果日期在array
中,则返回false,但每次在某些代码中尝试array
时,它会破坏选择器。我必须承认我完全不了解Javascript,只在必要时使用插件,感谢任何帮助。
spanner
我想禁用var dateToday = new Date();
var dates = $("#from, #to").datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 1,
minDate: dateToday,
onSelect: function(selectedDate) {
var option = this.id == "from" ? "minDate" : "maxDate",
instance = $(this).data("datepicker"),
date = $.datepicker.parseDate(instance.settings.dateFormat || $.datepicker._defaults.dateFormat, selectedDate, instance.settings);
dates.not(this).datepicker("option", option, date);
}
});
到2nd of December 2017
答案 0 :(得分:1)
$('#datePick').datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 1,
minDate: new Date(),
beforeShowDay: function(date){
var val = new Date("2017-12-02") >= date || new Date("2018-01-28") < date ;
return [ val ]
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js"></script>
<link href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/themes/redmond/jquery-ui.css" rel="stylesheet"/>
// disabled 2nd of December 2017 to January 27th 2018<br>
<input id='datePick'>
使用beforeShowDay
并检查您需要显示的日期。