Jquery UI 日期选择器禁用特定日期和所有日期(星期一和星期二)
Jquery UI Datepicker disable specific days and all (Mondays&Tuesday)
我想禁用特定日期和所有日期(星期一和星期二),例如
var array = ["2020-03-14","2020-03-15","2020-03-16"]
$('#datepicker').datepicker({
beforeShowDay: function(date){
var string = jQuery.datepicker.formatDate('yy-mm-dd', date);
var day = date.getDay();
if (day != 1 && day != 2)
return [true]
else if ( array.indexOf(string) == -1)
return [ true]
else
return [ false]
}
});
但它仅禁用 "2020-03-16" 怎么了?
考虑以下代码。
jQuery(function($){
var arr = [
"2020-03-14",
"2020-03-15",
"2020-03-16"
];
$('#datepicker').datepicker({
beforeShowDay: function(dt){
var dStr = $.datepicker.formatDate('yy-mm-dd', dt);
var day = dt.getDay();
var result = [false, ""];
if (day != 1 && day != 2){
result = [true, "available"];
}
if(arr.indexOf(dStr) >= 0){
result = [true, ""];
}
return result;
}
});
});
beforeShowDay
A function that takes a date as a parameter and must return an array with:
[0]
: true
/false
indicating whether or not this date is selectable
[1]
: a CSS class name to add to the date's cell or ""
for the default presentation
[2]
: an optional popup tooltip for this date
https://api.jqueryui.com/datepicker/#option-beforeShowDay
您必须 return 正确的数组。
我想禁用特定日期和所有日期(星期一和星期二),例如
var array = ["2020-03-14","2020-03-15","2020-03-16"]
$('#datepicker').datepicker({
beforeShowDay: function(date){
var string = jQuery.datepicker.formatDate('yy-mm-dd', date);
var day = date.getDay();
if (day != 1 && day != 2)
return [true]
else if ( array.indexOf(string) == -1)
return [ true]
else
return [ false]
}
});
但它仅禁用 "2020-03-16" 怎么了?
考虑以下代码。
jQuery(function($){
var arr = [
"2020-03-14",
"2020-03-15",
"2020-03-16"
];
$('#datepicker').datepicker({
beforeShowDay: function(dt){
var dStr = $.datepicker.formatDate('yy-mm-dd', dt);
var day = dt.getDay();
var result = [false, ""];
if (day != 1 && day != 2){
result = [true, "available"];
}
if(arr.indexOf(dStr) >= 0){
result = [true, ""];
}
return result;
}
});
});
beforeShowDay
A function that takes a date as a parameter and must return an array with:
[0]
:true
/false
indicating whether or not this date is selectable
[1]
: a CSS class name to add to the date's cell or""
for the default presentation
[2]
: an optional popup tooltip for this date
https://api.jqueryui.com/datepicker/#option-beforeShowDay
您必须 return 正确的数组。