如何限制 jQuery UI 日期选择器仅选择接下来 6 个月?

发布于 2024-12-31 20:54:07 字数 420 浏览 1 评论 0原文

我制作了一个 jQuery UI Datepicker 脚本,如下所示,仅选择周末。

    function onlyWeekends(date) {
        var day = date.getDay();
        return [(day == 0 || day == 6), ''];
    }

    $(function(){
        // Datepicker
        $('.datepicker').datepicker({
            dateFormat: "dd-mm-yy",
            beforeShowDay: onlyWeekends
        });
    });

但现在我想再添加一项限制,即仅选择当前日期后 6 个月内的日期。我怎样才能做到这一点?

I have made a jQuery UI Datepicker script as below to select only Weekends.

    function onlyWeekends(date) {
        var day = date.getDay();
        return [(day == 0 || day == 6), ''];
    }

    $(function(){
        // Datepicker
        $('.datepicker').datepicker({
            dateFormat: "dd-mm-yy",
            beforeShowDay: onlyWeekends
        });
    });

But now I want to add one more restriction into this, which is, select date only up-to next 6 months from current date. How can I do that?

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

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

发布评论

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

评论(1

陌伤ぢ 2025-01-07 20:54:07

配置 .datepicker() 对象时,可以使用 maxDate 和 minDate 选项。请参阅此处的精美手册

但基本上:

$( ".selector" ).datepicker({ maxDate: '+6m' });

There are maxDate and minDate options available when configuring a .datepicker() object. See here in the fine manual.

But basically:

$( ".selector" ).datepicker({ maxDate: '+6m' });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文