[英]Set allow time in jQuery Ui Timepicker
I'm using Timepicker to jQuery UI Datepicker https://trentrichardson.com/examples/timepicker/我正在使用 Timepicker 到 jQuery UI Datepicker https://trentrichardson.com/examples/timepicker/
jQuery('#element').datetimepicker({
dateFormat: "dd/mm/yy",
timeFormat: "H:m",
onSelect: function (selectedDateTime){
},
beforeShowDay: function(date) {
}
});
Now I want allow only 08:00 and 10:00 in timepicker, how can I do it?现在我只想在 timepicker 中允许 08:00 和 10:00,我该怎么做?
Thanks谢谢
According to provided documentation you have to use 2 properties minTIme
and maxTime
.根据提供的文档,您必须使用 2 个属性
minTIme
和maxTime
。 Smth like this:像这样:
<input type='text' class='timepicker' />
$('.timepicker').timepicker({
timeFormat: 'h:mm p',
interval: 60,
minTime: '08:00',
maxTime: '10:00',
defaultTime: '9',
startTime: '80:00',
dynamic: false,
dropdown: true,
scrollbar: true
});
===EDIT=== ===编辑===
In this case I'd suggest you to create change
handler for this timepicker and set it's value to default if wrong time was entered.在这种情况下,我建议您为此时间选择器创建
change
处理程序,并在输入错误时间时将其值设置为默认值。
$('.timepicker').timepicker({
timeFormat: 'h:mm p',
interval: 60,
minTime: '08:00',
maxTime: '10:00',
defaultTime: '9',
startTime: '80:00',
change: function(time) {
debugger;
if (time.getMinutes() !== 0) {
alert('Wrong value');
$('.timepicker').val('08:00');
}
}
});
Just use options: showmMinute: false
and stepHour: 2
只需使用选项:
showmMinute: false
和stepHour: 2
https://trentrichardson.com/examples/timepicker/ https://trentrichardson.com/examples/timepicker/
See code below:见下面的代码:
$('.timepicker').timepicker({
timeFormat: 'h:mm p',
interval: 60,
minTime: '08:00',
maxTime: '10:00',
startTime: '8:00',
showMinute: false,
stepHour: 2
});
Added JSfiddle: https://jsfiddle.net/wvt2bnok/添加 JSfiddle: https ://jsfiddle.net/wvt2bnok/
I used this library and it working fine with allowTimes option.我使用了这个库,它与 allowTimes 选项一起工作得很好。 https://xdsoft.net/jqplugins/datetimepicker/
https://xdsoft.net/jqplugins/datetimepicker/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.