html - 如何显示输入时间显示M:S.ms(分钟:秒.milisecond)?

时间:2018-04-09 07:20:38

标签: javascript html time

我如何在html中输入时间?

我希望输入的格式是MM:SS.ms。

我想在https://www.olympic.org/pyeongchang-2018/results/en/alpine-skiing/results-men-s-downhill-trno-000100-.htm

中制作时间表
MM: minutes
SS: second
ms: milisecond

这是我到目前为止所做的事情

<style type="text/css">
    #time1, #time2 {
        width: 125px;
    }        
</style>

<form>
    <label for="time1">Result </label>
    <input id="time1" type="text" name="time1">
    <input type="checkbox" onclick="enableInputTime('time1')"> Input Time?
    <br>
    <label for="time2">Result </label>
    <input id="time2" type="text" name="time2">
    <input type="checkbox" onclick="enableInputTime('time2')"> Input Time?

</form>

<script type="text/javascript">

    function enableInputTime(id) {
        var id = document.getElementById(id);
        if(id.type === 'text') {
            id.type = 'time';
            id.step = "0.1";
        } else {
            id.type = 'text';
            id.list = "Options";
        } 
    }

</script>

1 个答案:

答案 0 :(得分:1)

<input id=foo name=foo type=time min="0:00" max="120:00">

https://jsfiddle.net/tz35nqso/

我知道HTML5有一个输入时间元素,但您必须删除毫秒字段。否则请使用第三方库,就像其他人建议的那样。