【发布时间】:2018-04-09 07:20:37
【问题描述】:
如何在html中输入时间?
我希望输入的格式是 MM:SS.ms。
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>
【问题讨论】:
-
还可以看看 moment.js 库,它有助于格式化
-
@lovemyjob 问题是我不应该使用任何插件/框架。我正在尝试输入不从当前日期时间获取值
标签: javascript html time