1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【HTML5】Input type="time"で入力値「00:00:00」としたときのvalueの値が「00:00」になる。

Posted at

メモとして残します。

Input要素で type="time"でstep属性の値「1」にした場合、
「00:00:00」の形式で秒までの入力が可能となります。
しかし、ここにトラップがありました。
結論はタイトルの通り
入力値「00:00:00」としたときのvalueの値が「00:00」になります。

■対策

  $('body').on('change','input[type="time"][step="1"]',function(){
    $(this).val($(this).val()=='00:00'?'00:00:00':$(this).val())
  });

今時jQueryですみません。
たまたま、発見したシステムで使用されていたので(;^ω^)

■さいごに

step属性の値が0.1でも同様の現象になるため、注意。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?