如何强制秒在HTML5“时间”上显示输入控制? [英] How do I force seconds to appear on an HTML5 "time" input control?

查看:609
本文介绍了如何强制秒在HTML5“时间”上显示输入控制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用Javascript设置HTML5time对象的值时,像这样:

When I use Javascript to set the value of an HTML5 "time" object, like this:

document.getElementById("settime").value = "13:24:59";

它会在时间控制上显示13:24:59,我可以改变一切。但是,如果我这样做:

It will show a time control with "13:24:59" on it, and I can change everything. But if I do this:

document.getElementById("settime").value = "13:25:00";

它隐藏秒数,只显示13:25,没有秒。如何强制在这种情况下出现00秒?

It hides the seconds, showing just "13:25" with no seconds. How do I force the "00" seconds to appear in this case?

(顺便说一下,这是在Google Chrome中。)

(This is in Google Chrome, by the way.)

推荐答案

设置步骤属性

例如:< input id =settimetype =timestep =1/>

jsFiddle示例

jsFiddle example

注释关于步骤属性

step属性可与数字输入值一起使用,以指示您可以输入的值的粒度。例如,您可能希望用户输入特定的时间,但只能以30分钟的增量进行输入。在这种情况下,我们可以使用step属性,请记住,对于时间输入,属性的值以秒为单位。例如,30分钟的增量将具有1800的步长值。< input type =timestep =1800>

The step attribute can be used with a numerical input value to dictate how granular the values you can input are. For example, you might want users to enter a particular time, but only in 30 minute increments. In this case, we can use the step attribute, keeping in mind that for time inputs the value of the attribute is in seconds. For example, a 30 minute increment would have a step value of 1800. <input type="time" step="1800">

这篇关于如何强制秒在HTML5“时间”上显示输入控制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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