繁体   English   中英

在 html 输入日期时间本地选择器中禁用上一个今天的上一个时间

[英]Disable previous today's previous time in html input datetime-local picker

我正在尝试找出解决方案来解决不允许用户选择上一次的问题。 我的意思是例如

今天日期:17-02-2019
当前时间:02:30 PM

因此,当用户选择今天的日期并选择时间 02:30 AM 而不是 PM。 此处时间已过,因此不应允许用户选择 AM 时间,因为当前时间是 02:30 PM

根据 MDN 文档,下面的代码应该可以工作,但它不工作。

   <input type="datetime-local" min="2019-02-17T14:30" />

根据以下文档,它不应该允许我选择时间,例如上午 9:00、上午 10:00 甚至下午 2:29,但我可以选择。 我什至尝试了他们的小提琴示例,但他们的示例确实让我可以选择过去的时间

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/datetime-local

这可能是由于格式的原因,您可能需要去掉秒数。 在 console.log 中,您可以看到秒数,但是在设置min时,需要去掉秒数和微秒数

 var today = new Date().toISOString(); console.log(today) document.getElementById("daTi").min = '2019-02-17T10:38';
 <input type="datetime-local" id='daTi' />

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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