如何使用 jQuery 中的日期选择器从两个日期范围中进行选择?

发布于 2024-08-23 19:40:35 字数 638 浏览 7 评论 0原文

我正在使用 jQuery Datepicker(http://keith-wood.name/datepick.html )。我试图让用户从两个不同的日期范围中选择一个日期。我在文档中找不到该功能,我想知道如何实现这一点。

我想让用户选择当前日期后的 1-5 天。我也不想让用户选择周末的日子。我想出了如何使用以下设置来做到这一点:

$("#rush_needed_by_english").datepick({
  minDate: +1,
  maxDate: +5,
  beforeShowDay: $.datepick.noWeekends
});

现在,如果当天是星期四,则仅允许用户选择星期五、星期一和星期二,因为它设置为仅允许 1当日后-5 天可选择,但周六和周日不可选。

就我的示例而言,我想要的是完全跳过周末并选择周五和周一至周四。或者,如果这是不可能的,我想设置两个不同的日期范围以供选择。因此,根据我的示例,我将使用 javaScript 查找当前日期(星期四),然后创建两个可选择的日期范围(星期五和星期一至星期四)。

如何跳过周末,以便在跳过周末时可选择 5 天?

I am using the jQuery Datepicker(http://keith-wood.name/datepick.html). I am trying to let the user pick a date from two separate ranges of days. I can't find that feature in the documentation and I would like to know how to make that possible.

I want to let the user pick from 1-5 days after the current date. I also don't want to allow the user to pick days on the weekend. I figured out how to do that using the following settings:

$("#rush_needed_by_english").datepick({
  minDate: +1,
  maxDate: +5,
  beforeShowDay: $.datepick.noWeekends
});

As it is now, if the current day is a Thursday for example, it will only allow the user to pick Friday,Monday, and Tuesday since it is set up to only allow 1-5 days after the current day to be selectable, but Saturday and Sunday are not selectable.

As far as my example is concerned, what I would like is to either skip the weekend days completely and make Friday and Monday-Thursday selectable. Or if that is not possible, I would like to set the two different ranges of days to pick from. So per my example, I would use javaScript to find the current day(Thursday), and then make two selectable ranges of dates(Friday AND Monday-Thursday).

How can I skip the weekend days so 5 days are selectable while skipping over the weekend days?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沐歌 2024-08-30 19:40:35

我发现我可以将 MaxDate 延长一定天数来模拟跳过周末。任务解决了!

I figured out I can just extend the MaxDate by a certain number of days to simulate skipping over the weekend days. Mission Solved!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文