为Materialise Clockpicker设置时间格式'HH:MM:SS'

时间:2017-06-05 11:43:17

标签: javascript jquery materialize

我已添加以下库

<link rel="stylesheet" href="assets/plugins/timepicker/materialize.clockpicker.css"/>
<script src="assets/plugins/timepicker/materialize.clockpicker.js"></script>

使用Jquery库。

我的输入元素是

<input id="default_start_time" name="default_start_time" class="timepicker" type="time">

脚本部分

$('.timepicker').pickatime({
        default: 'now',
        twelvehour: false, // change to 12 hour AM/PM clock from 24 hour
        donetext: 'OK',
        format:"HH:ii:SS",
        autoclose: false,
        vibrate: true 
    });

我也试过

$('.timepicker').pickatime({
        default: 'now',
        twelvehour: false, // change to 12 hour AM/PM clock from 24 hour
        donetext: 'OK',
        format:"HH:MM:SS",
        autoclose: false,
        vibrate: true 
    });

但是时间选择器允许返回小时:分钟格式(如08:10,19:06)

问题是什么?

2 个答案:

答案 0 :(得分:2)

您可以尝试一些小的解决方法,使用step="1"

<input id="default_start_time" name="default_start_time" class="timepicker" type="time" step="1">

但是,datetime输入和pickatime通常不支持秒,请参阅http://amsul.ca/pickadate.js/time/#formatshttp://amsul.ca/pickadate.js/time/#formatting-rules

https://github.com/chingyawhao/materialize-clockpicker

打开问题可能是个好主意

答案 1 :(得分:2)

实现clockpicker dosent支持秒,但您可以通过添加简单的jquery代码来获得所需的结果。

$(document).ready(function() {
    $('.timepicker').pickatime({
        default: 'now',
        twelvehour: false, // change to 12 hour AM/PM clock from 24 hour
        donetext: 'OK',
        format: "HH:ii:SS",
        autoclose: false,
        vibrate: true
    });
    // For adding seconds (00)
    $('.timepicker').on('change', function() {
        let receivedVal = $(this).val();
        $(this).val(receivedVal + ":00");
    });
});