gpt4 book ai didi

javascript - jquery 日期选择器 : weird documentation substraction in minDate

转载 作者:行者123 更新时间:2023-12-03 11:10:10 24 4
gpt4 key购买 nike

我刚刚读过the official docs for jQuery's datepicker, in particular the minDate setting ,其中包含以下代码片段:

$( ".selector" ).datepicker({
minDate: new Date(2007, 1 - 1, 1)
});

有人可以向我解释一下上面的 1 - 1 的意义是什么吗?据我了解,在 JavaScript 中,这将被评估为零,这对于日期中的一个月来说没有意义。

谢谢

PS:这看起来不像是一个拼写错误,因为在后面的几行中重复了同样的事情。

最佳答案

月份从 0 开始,因此如果您想将日期设置为 2007 年 1 月 1 日,则必须使用

new Date(2007, 0, 1)

这相当于

new Date(2007, 1 - 1, 1)

阅读Docs

month: Integer value representing the month, beginning with 0 for January to 11 for December.

关于javascript - jquery 日期选择器 : weird documentation substraction in minDate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27637157/

24 4 0
文章推荐: javascript 如何从一个数组填充相互依赖的