我想在datepicker日历中禁用某些数组日期。但是这些日期不会在日历中禁用。我已经包含了日历所需的所有jQuery文件。
脚本
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js"></script>
html
<input class="form-control time_slot_searchField" id="datepicker" name="" type="text" required="" style="">
禁用日期数组的脚本
$('#datepicker').datepicker({
beforeShowDay: function(date) {
var day = jQuery.datepicker.formatDate('dd-mm-yy', date);
return [!~$.inArray(day, exclude) && (date.getDay() != 0)];
}
});
问题出在哪里。有冲突吗?
有人帮忙吗?预先感谢
答案 0 :(得分:0)
您的代码在return [!~$.inArray(day, exclude) && (date.getDay() != 0)];
处出错
将代码更改为
var day = jQuery.datepicker.formatDate('yy-mm-dd', date);
return [ exclude.indexOf(day) == -1 ]
var exclude = ["2019-06-06","2019-06-25","2019-06-28"]
$('input').datepicker({
beforeShowDay: function(date){
var day = jQuery.datepicker.formatDate('yy-mm-dd', date);
return [ exclude.indexOf(day) == -1 ]
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js"></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<input class="form-control time_slot_searchField" id="datepicker" name="" type="text" required="" style="">