![](/img/trans.png)
[英]How to disable dates more than 1year from the current date in the datetime-local TextField
[英]How do I disable dates till current date? For input Type Datetime-local
我正在使用 Modal 作為任務的提醒日期。 當前日期及其前幾天必須被禁用,以便用戶可以選擇從第二天開始的取件日期,以便用他指定的任務標記提醒。
為此,我使用輸入類型: <input type="datetime-local" class="form-control" autocomplete="off" id="actionreminderdate" />
如果我使用下面的 java 腳本,它適用於輸入類型“Date”,但不適用於 Datetime-local。
$(function(){
var dtToday = new Date();
var month = dtToday.getMonth() + 1;
var day = dtToday.getDate();
var year = dtToday.getFullYear();
if(month < 10)
month = '0' + month.toString();
if(day < 10)
day = '0' + day.toString();
var maxDate = year + '-' + month + '-' + day;
/*alert(maxDate);*/
$('#actionreminderdate').attr('min', maxDate);
});
你能幫我解決嗎?
您可以在輸入字段上設置最小值和最大值:
<input type="datetime-local" id="dateInput">
$(document).ready(function(){
elem = document.getElementById("dateInput")
var iso = new Date().toISOString();
var minDate = iso.substring(0,iso.length-1);
elem.value = minDate
elem.min = minDate
});
以可識別的 ISO 格式獲取當前時間(您必須在末尾修剪區域數據,這很煩人),然后將其設置為輸入值和輸入最小值。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.