admin管理员组

文章数量:1328022

HTML5 type=time has a property disabled which disables the field, but is there any specific way to disable only the hours or only the minutes from the field?

<input type='time' />

HTML5 type=time has a property disabled which disables the field, but is there any specific way to disable only the hours or only the minutes from the field?

<input type='time' />
Share Improve this question edited Aug 29, 2019 at 8:28 sSD asked Aug 29, 2019 at 8:01 sSDsSD 2921 gold badge2 silver badges17 bronze badges 2
  • What did u try ? – user4431269 Commented Aug 29, 2019 at 8:05
  • @PhilAndelhofs, was thinking to block using css, but could not get hold of the dom element specific to the hours or minutes entry field. – sSD Commented Aug 29, 2019 at 8:12
Add a ment  | 

2 Answers 2

Reset to default 6

You can definitely lock the minutes so they can't be changed and only hours can be adjusted, just change the step:

For example:

<input type='time'  step='3600'/>

<input type='time'  step='3600'/>

To acplish only using minutes, you can technically do this by maxing and mining the time:

<input type='time'  max='00:59' min='00:00'/>

step is the attribute you are looking for.

The step attribute indicate what the minimum increment should be in seconds. If set to 60, the increment will always be 60 seconds - in other words, seconds cannot be changed. To make the minutes too cannot be changed, use step="3600".

<form>
  <label for="appt-time">Choose an appointment time: </label>
  <input id="appt-time" type="time" name="appt-time" step="3600">
</form>

本文标签: javascriptIs there a way to disable the minutes or hours selection only for html5 typetimeStack Overflow