简体   繁体   中英

Can an html input element with a type of time have a default value?

Should the following code work to set a default time? If not, is there a way to make it work strictly with html and no Javascript?

<input type="time" name="time" id="whatever" value="1:10">

When I manually set a time to the widget and use document.getElementById("whatever").value to output the value I get a string that uses military time to denote am/pm.

Thank you.

You need to use HH:MM format, so:

<input type="time" name="time" id="whatever" value="13:10">

for 1PM or:

<input type="time" name="time" id="whatever" value="01:10">

for 1AM .

Demo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM