禁用一周中的日子,用react-datepicker
我只想禁用我选择的一周中的日子,或者以其他方式启用我
在这里需要的日子是说明性图像
我在文档中找到了此代码,但它不适用于我
() => {
const [startDate, setStartDate] = useState(null);
const isWeekday = (date) => {
const day = getDay(date);
return day !== 0 && day !== 6;
};
return (
<DatePicker
selected={startDate}
onChange={(date) => setStartDate(date)}
filterDate={isWeekday}
placeholderText="Select a weekday"
/>
);
};
I only want to disable the days of the week that I choose, or otherwise enable the days that I need
here is an illustrative image
I found this code in the documentation but it doesn't work for me
() => {
const [startDate, setStartDate] = useState(null);
const isWeekday = (date) => {
const day = getDay(date);
return day !== 0 && day !== 6;
};
return (
<DatePicker
selected={startDate}
onChange={(date) => setStartDate(date)}
filterDate={isWeekday}
placeholderText="Select a weekday"
/>
);
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将一周中的一天更改为此示例来自行的文档
返回日!== 0&amp;&amp; Day!== 6;
通过更改最后一个数字。例如,将
Day!== 6
更改为day!== 7
将仅排除周日,等等。 >&amp;&amp; Day!== [Day Number] 回到回调。例如
day!== 0&amp;&amp; Day!== 2&amp;&amp; Day!== 5;
将排除周日,星期二&amp;星期五。You can change the day of the week to disable in this example from the docs on the line
return day !== 0 && day !== 6;
by changing the last number.For instance, changing
day !== 6
today !== 7
will exclude only Sundays, etc.If you want to exclude multiple days of the week, add
&& day !== [day number]
to the callback. For instanceday !== 0 && day !== 2 && day !== 5;
will exclude Sundays, Tuesdays & Fridays.我有很简单的解决方案:
现在您可以轻松地通过一周的日子
I have solution that is quite simple:
Now you can easily pass an array of the days of the week