Bootstrap DateTimePicker禁用分钟 [英] Bootstrap datetimepicker disable minutes

查看:333
本文介绍了Bootstrap DateTimePicker禁用分钟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 https://github.com/Eonasdan/bootstrap-datetimepicker 中的v4 。现在,我尝试在时间选择上禁用分钟选择器。我知道我可以使用:

I am using v4 from https://github.com/Eonasdan/bootstrap-datetimepicker. Now I am trying to disable the minutes-selector on time-selection. I know I could use:

$(this).datetimepicker({
  format: 'HH'
});

但是使用此代码,分钟数根本不会显示。我想在选择器中显示分钟,但将其禁用。有实现这一目标的机会吗?

But with this code, minutes aren't shown at all. I would like to show minutes in the selector, but disable it. Any chance to achieve that?

推荐答案

我尝试使用 dp.show dp.change 事件来处理它。

I tried using dp.show and dp.change events to handle it.

在show event中,分钟元素被禁用,以避免分钟更改并采用小时部分,然后跟随:00

In the show event minutes element are disabled in order to avoid minutes changing and the hour part is taken and followed by :00.

代码:

$('#datetimepicker1').datetimepicker();
$('#datetimepicker2').datetimepicker({
    format: 'HH:mm'
}).on('dp.show', function () {
    $('a.btn[data-action="incrementMinutes"], a.btn[data-action="decrementMinutes"]').removeAttr('data-action').attr('disabled', true);
    $('span.timepicker-minute[data-action="showMinutes"]').removeAttr('data-action').attr('disabled', true).text('00');
}).on('dp.change', function () {
    $(this).val($(this).val().split(':')[0]+':00')
    $('span.timepicker-minute').text('00')
});

演示: http://jsfiddle.net/mfjvnh9a/

这篇关于Bootstrap DateTimePicker禁用分钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆