问题
I am using Modal for reminder date for task. The current date and the days before it has to be disabled so that the User can select the pick-up date starting next day inorder to Mark reminder with his specified task.
for this I am using input type :
<input type="datetime-local" class="form-control" autocomplete="off" id="actionreminderdate" />
If I use below java script it works for input type "Date" But not for 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);
});
Can you help me with it?
回答1:
You can set min and max values on the input field:
<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
});
Get the current time in a recognised ISO format (you have to trim the zone data off the end, which is annoying), then set that as the input value and the input min.
https://jsfiddle.net/w8qgj543/24/
来源:https://stackoverflow.com/questions/50718968/how-do-i-disable-dates-till-current-date-for-input-type-datetime-local