0

我在初始化“From”和“To”日期时间选择器时设置了 minDate(2019-06-21) 和 maxDate(today)。When select time interval to month, Will format the datetimepicker to "MMM YYYY". 然后我只能在日历小部件中选择 Jul,尽管 Jun 也处于活动状态并且应该是可选的。

但是如果我在 datetimepicker 初始化代码中添加“useCurrent: false”,日历将允许用户只选择 Jun 而不是 Jul。

代码在这里:

enter code here
 https://jsfiddle.net/srcuz3fm/

由于 minDate 是 2019 年 6 月 21 日,而 maxDate 是今天(2019 年 7 月 23 日),所以无论 useCurrent 是真还是假,所有用户都应该从日历小部件中选择 Jun 或 Jul。

4

1 回答 1

0

After days of trys, I figures out how to fix this issue. BAsically, the reason cause the problem is when change datetimepicker format, it'll set the year to the morning midnight of new year day. Since I set the minDate in the initial settings which is "2019-06-21", so the datetimepicker won't allow me to select 2019.

So I added these in the javascript together right before the format,

$("#datetimepicker2").datetimepicker("minDate", moment(startdate).startOf("year")); $("#datetimepicker3").datetimepicker("minDate", moment(startdate).startOf("year")); $("#datetimepicker2").datetimepicker("maxDate", moment(today).endOf("year")); $("#datetimepicker3").datetimepicker("maxDate", moment(today).endOf("year"));

Here is the link to working code in jsfiddle

于 2019-07-30T19:29:06.103 回答