![](/img/trans.png)
[英]How to disable previous date using HTML5 datetime-local input?
[英]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.