输入=时间,如何只允许输入小时.没有分钟或几秒钟 [英] Input = time, How to allow input of only the hour. No minutes or seconds
问题描述
我想允许用户输入时间,但只允许输入小时,不能输入分钟或秒.我知道文本或数字字段会更好,但需要将输入内容作为时间发布.
I want to allow the user to input a time but only allow the input of hours, no minutes or seconds. I understand a text or number field would be better but need to post the input as a time.
我尝试将step属性设置为600,但是只删除了毫秒.
I have tried setting the step attribute to 600, however that removes the milliseconds only.
推荐答案
step属性是您可以执行的步数(以毫秒为单位),因此在这种情况下,您应该使用 60 * 60 * 1000
(60分钟* 60秒* 1000毫秒= 1小时)作为值:
The step attribute is the step amount you can do in milliseconds, so in this case you should use 60 * 60 * 1000
(60 minutes * 60 seconds * 1000 milliseconds = 1 hour) as the value:
<input type="time" step="3600000" />
请注意,这在Safari中不起作用,但是我确实在Chrome中对其进行了测试.Safari根本不支持这种类型,所以据我所知,没有任何验证发生.这使得它不能普遍兼容.
Note that this does not work in Safari, but I did test it in Chrome. Safari simply doesnt support this type at all, so no validation happens as far as I can see. Which makes this not universally compatible.
这篇关于输入=时间,如何只允许输入小时.没有分钟或几秒钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!