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

∥☆過路亽.° 提交于 2020-01-24 16:57:10

问题


I am trying to figure out solution to fix the issue of not allowing user to select previous time. I mean for eg

Today's date: 17-02-2019
Current Time: 02:30 PM

So when user selects today's date and selects the time 02:30 AM instead of PM. Here the time is past so user shouldn’t be allowed to select the AM time because the current time is 02:30 PM

As per MDN docs the below code should work but it’s not working.

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

As per below docs it shouldn’t allow me to select time like eg 9:00 AM, 10:00 AM even 02:29 PM but I am allowed to select. I even tried their fiddle example but their examples do allow me to select past time

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


回答1:


This may be because of the format , you may need to strip off the seconds. In console.log you can see the seconds but when setting the min value the seconds and microseconds need to strip off

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


来源:https://stackoverflow.com/questions/54732299/disable-previous-todays-previous-time-in-html-input-datetime-local-picker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!