1

我有两个时间选择器,第一个是“从”时间,第二个是“到”时间。
What I was trying to achieve was that when the 'from' time was picked, the 'to' time would then disable all times before the 'from' time and if the 'to' time was before the newly selected 'from' time,它会在“从”时间后 15 分钟更新“到”时间。

更改选择的值并禁用时间在彼此独立时可以完美地工作,但是当它们一起使用时,时间总是恢复到下午 1:30,这看起来像选择中的中值。

我最终弄清楚了这一点,并在下面为遇到此问题的其他人发布了答案。

4

1 回答 1

1

所以我最终发现这disable是导致问题的函数,我最初是disable在检查时间的当前值to是否小于当时的时间之前设置from时间。

禁用时间时,pickatime会将当前设置的时间重置为中值,对我来说是下午 1:30。

我需要做的就是在禁用任何时间之前将时间to相对于新时间增加 15 分钟。from

我的代码最终解决了问题

jQuery('#datetimepicker' + COUNT + '1' + ' input').on('change', function()
        {
            var time = jQuery(this).pickatime('picker').get('select'),
                hour = time.hour,
                minute = time.mins,
                count = jQuery(this).data('count'),

            picker = jQuery('#datetimepicker' + count + '2' + ' input').pickatime('picker');
            picker.set('enable', true);

            if (picker.get('value') != '')
            {
                if (picker.get('select').time <= time.time)
                {
                    picker.set('select', time.time + 15);
                }
            }
            else
            {
                picker.set('select', time.time + 15);
            }

            picker.set('disable',[{from: [7, 0], to: [hour, minute]}]);

            picker.render;
        });

希望这可以节省其他人处理这个问题的时间。:)

于 2016-08-30T03:22:36.240 回答