简体   繁体   中英

HTML input type “time” not taking default value

I'm trying to use an HTML input element with type="time" , but I'm getting unexpected results. I have two of these on a page, one of them works and one does not.

 <td> <input type="time" class="uk-input" value="7:30:00" name="timein[]"/> </td> <td> <input type="time" class="uk-input" value="16:00:00" name="timeout[]"/> </td> 

The first element will be rendered blank, why?

2 digits per number. Just add a 0 in front of 7. the format is hh:mm:ss .

Here is doc .

 <input type="time" class="uk-input" value="07:30:00" name="timein[]"/> <input type="time" class="uk-input" value="16:00:00" name="timeout[]"/> 

You need to set a valid time string . So you missed the 0 in front of 7 :

 <input type="time" class="uk-input" value="07:30:00" name="timein[]"/> <input type="time" class="uk-input" value="16:00:00" name="timeout[]"/> 


A string is a valid time string representing an hour hour, a minute minute, and a second second if it consists of the following components in the given order:

  • Two ASCII digits, representing hour, in the range 0 ≤ hour ≤ 23
  • A U+003A COLON character (:)
  • Two ASCII digits, representing minute, in the range 0 ≤ minute ≤ 59
  • If second is nonzero, or optionally if second is zero:
    • A U+003A COLON character (:)
    • Two ASCII digits, representing the integer part of second, in the range 0 ≤ s ≤ 59

source: https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-time-string

So the following values are valid:

 <input type="time" value="07:30:00"/> <input type="time" value="07:30:01"/> <input type="time" value="07:30"/> <input type="time" value="17:30:00"/> <input type="time" value="17:30:01"/> <input type="time" value="17:30"/> 

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