我想知道是否可以在没有小时的情况下强制输入类型时间,它只以“mm:ss”格式显示“00:00”。可能吗?
谢谢。
max
和中的格式min
错误
像这样试试
<input type="time" step='1' min="00:00:00" max="20:00:00">
这里的问题是,你也许可以使用一些智能 JavaScript 来做到这一点,但是当涉及到跨浏览器兼容性时,你会发现自己处于一个棘手的境地,而且如果你需要支持像 IE8 这样的旧浏览器,它们不支持 HTML5全部。
你到底想做什么?
对于一个好的普通JS(<3)后备,我基本上会做一些简单的事情:
function getCurrentTime() {
//Create a new date object.
var oTime = new Date();
//Get the minutes from the current date object.
var minutes = oTime.getMinutes();
//Get the seconds from the current date object.
var seconds = oTime.getSeconds();
//Optional: Add leading zero's
if (minutes < 10)
minutes = '0'+minutes;
if (seconds < 10)
seconds = '0'+seconds;
//Return the current minutes and seconds
return minutes+':'+seconds;
}
例如,您可以创建一个函数,将上述结果放在输入字段中,但是如果您寻找其他时间,例如将来的某个时间,这是当前时间,这有点不同,所以我不会去那里吧:)