在日期时间本地 HTML 中预选择分钟值

问题描述 投票:0回答:1

我需要从本地日期时间中选择日期,但我希望将分钟预选为“00”

喜欢: 月/日/年 --:--:00

这样,如果用户选择日期时间,分钟将始终设置为 00。

我的HTML代码是:

<input type="datetime-local" name="datetime_regular_start" id="datetime_regular_start" value="" required>

我已经尝试过了

const dateControl = document.querySelector('input[type="datetime-local"]');
dateControl.value = "2020-06-01T08:30";

并且整个日期时间值是预先选择的,

所以我尝试只将分钟更改为 00。

const dateControl = document.querySelector('input[type="datetime-local"]');
dateControl.value = "yyyy-mm-dd-HH:00";

但是它不起作用。我应该如何将分钟值设置为始终 00?

html datetime-local
1个回答
0
投票

您可以将

step
属性设置为 3600 秒(即一小时):

<input type="datetime-local" step="3600">

© www.soinside.com 2019 - 2024. All rights reserved.