twitter-bootstrap 如何限制引导时间选择器的最小时间和最大时间?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29716211/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to restrict the bootstrap timepicker min-time and max-time?
提问by Manjit singh
I am using bootstrap time picker by using bootstrap-timepicker.js and i want to restrict the min-time and max-time of that timepicker .Can anyone please tell me how can i achieve it. I have used following methods but nothing gonna help me out:
我正在通过使用 bootstrap-timepicker.js 使用引导时间选择器,我想限制该时间选择器的最小时间和最大时间。谁能告诉我如何实现它。我使用了以下方法,但没有任何帮助:
$('input[data-role="time"]').timepicker({
showMeridian: true,
minTime: {
hour: 10,
minute: 15
},
minuteStep: 1,
showInputs: true,
defaultTime: defaulttime
})
And
和
$('input[data-role="time"]').timepicker({
showMeridian: true,
minTime: '10:15',
minuteStep: 1,
showInputs: true,
defaultTime: defaulttime
})
回答by dm4web
- use event
changeTime, - check the current time,
- if time is less set minimum
- 使用事件
changeTime, - 检查当前时间,
- 如果时间较短,则设置最小值
$('#timepicker').timepicker({
showMeridian: true,
minuteStep: 1,
showInputs: true,
}).on('changeTime.timepicker', function(e) {
var h= e.time.hours;
var m= e.time.minutes;
var mer= e.time.meridian;
//convert hours into minutes
m+=h*60;
//10:15 = 10h*60m + 15m = 615 min
if(mer=='AM' && m<615)
$('#timepicker').timepicker('setTime', '10:15 AM');
});
回答by Kelvline
You can use the following:eg if mindate is at 8.00 and maxdate is at 2300hrs
您可以使用以下内容:例如,如果 mindate 是 8.00 而 maxdate 是 2300hrs
minDate: moment({h:8}),
maxDate: moment({h:23}),
that is...
那是...
$('#time').bootstrapMaterialDatePicker({
format: 'HH:mm',
minDate: moment({h:8}),
maxDate: moment({h:23}),
clearButton: true,
date: false
});

