How to prevent jQuery bootstrap ClockPicker to get minutes that are not divisible by 5

后端 未结 2 740
青春惊慌失措
青春惊慌失措 2021-01-24 00:22

I am using jQuery bootstrap ClockPicker and need to get only times that their minutes are divisible by 5. For example if user selects 13:08, the ClockPicker should select 13:05.

2条回答
  •  隐瞒了意图╮
    2021-01-24 01:09

    I didn't found a way to do this with the API. So I wrote one using afterDone callback.

    I parse the input's value and make the change to get the new minutes value.

    var clockpicker = $('.clockpicker').clockpicker({
      afterDone: function() {
        clockpicker.val(round());
      }
    }).find('input');
    
    function round() {
      var time = clockpicker.val(),
          arr = time.split(':'),
          hour = arr[0],
          min = arr[1],
          newMin = (Math.floor(parseInt(min) / 5)) * 5;
    
      return hour + ':' + (newMin > 9 ? '' : '0') + newMin;
    }
    
    
    
    
    
    
    

    http://jsbin.com/lopufu/edit?html,js

提交回复
热议问题