无法让 jQueryUI 日期选择器显示我想要的日期范围

发布于 2025-01-04 09:30:05 字数 521 浏览 4 评论 0原文

我想附加 jQueryUI datepicker 控件,以便用户可以选择他们的出生日期。

这是我的 Javascript 代码:

<script type="text/javascript">
    $(document).ready(function() {
        $("#dob").datepicker({
            minDate: "-100Y", 
            maxDate: "+1M +10D",
            changeMonth: true,
            changeYear: true
        });
    });        
</script>

所以我希望用户能够选择一个日期,可以是 100 年前,也可以是一个月后。 (虽然如果我可以将最大范围限制为“今天”之前一年会更好)

我的 jQuery 选项有什么问题,它似乎没有听我想要的。

它显示从 2002 年到 2012 年的年份。

I'd like to attach the jQueryUI datepicker control so users can pick their date of birth.

Here is my Javascript code:

<script type="text/javascript">
    $(document).ready(function() {
        $("#dob").datepicker({
            minDate: "-100Y", 
            maxDate: "+1M +10D",
            changeMonth: true,
            changeYear: true
        });
    });        
</script>

So I want users to be able to select a date, that's either 100 years earlier or a month from now. (Although it would be better if I could limit the max range to be a year before "today")

What is wrong with my jQuery options, it just doesn't seem to listen to what I want.

It's displaying the years from 2002 to 2012.

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

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

发布评论

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

评论(1

眼泪也成诗 2025-01-11 09:30:05

它正在听你想要听的内容。我在 jsFiddle 中测试了你的源代码,它运行良好。

默认情况下,“年份”下拉列表一次仅显示 10 项。您可以使用yearRange 选项更改此设置(例如yearRange: 'c-100:c+10',)。

It is listening to what you want. I tested your source in jsFiddle, and it runs fine.

The "Year" dropdown will only display 10 items at a time by default. You can change this with the yearRange option (e.g., yearRange: 'c-100:c+10',).

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