我使用 bootstrap datetimepicker 来构建我的日期和时间选择器。
我在页面初始化中按如下方式制作时间选择器:
$('#PickupTime').datetimepicker({
locale: 'en',
format: 'hh:mm A',
stepping: 30,
});
我想根据集成返回的数据设置时间选择器的最短和最长时间。
$.ajax({
url: url,
data: data,
method: 'post',
success: function (result) {
debugger;
$('#PickupTime').datetimepicker({
disabledTimeIntervals: [[moment().hour(0), moment().hour(8).minutes(30)], [moment().hour(20).minutes(30), moment().hour(24)]],
});
},
});
但我注意到 disabledTimeIntervals
不起作用,
disabledTimeIntervals
仅当我将其放入初始化函数中时才起作用。
最佳答案
您必须使用disabledTimeIntervals
函数而不是 disabledTimeIntervals
选项。
请注意,如 docs说:
All functions are accessed via the
data
attribute e.g.$('#datetimepicker').data("DateTimePicker").FUNCTION()
您的代码将是:
$.ajax({
url: url,
data: data,
method: 'post',
success: function (result) {
debugger;
$('#PickupTime').data("DateTimePicker").disabledTimeIntervals([
[moment().hour(0), moment().hour(8).minutes(30)],
[moment().hour(20).minutes(30), moment().hour(24)]
]});
},
});
关于twitter-bootstrap - 初始化后设置选项时,datetimepicker 中的 disabledTimeIntervals 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43304664/