我想禁用所有周日在扁平的选择,这是正确的工作。但是现在我想定义一些例外,比如母亲节。这是我的代码,但是if-block总是会被执行,我仍然不能选择母亲节。
// Mothers Day -> dd.mm.yyyy
const d = new Date();
d.setMonth(4); // May
d.setDate(8); // May 8 is the earliest possible date
// while not a sunday, move to next day
while (d.getUTCDay()) d.setDate(d.getDate() + 1);
const motherDayDate = new Intl.DateTimeFormat('de-DE', { day: "2-digit", month: "2-digit", year: "numeric"}).format(d);
$(".datePicker").flatpickr({
enableTime: false,
dateFormat: "d.m.Y",
minDate: "today",
"locale": {
"firstDayOfWeek": 1
},
"disable": [
function(date) {
// motherDayDate = e.g. 09.05.2021
if (moment(date).format("DD.MM.YYYY") === motherDayDate){
alert ("mother");
return true;
}
// 0 = Sunday
return (date.getDay() === 0);
}
]
});发布于 2021-05-10 04:10:45
我不太熟悉flatpickr,但也许您应该在代码alert("mother");下面返回false
(如果我有足够的声誉,我会把这篇文章作为评论发布的。不过,希望这能有所帮助!)
https://stackoverflow.com/questions/67461900
复制相似问题