我有一个输入类型日期,我选择日期。我希望可以选择的日期是从现在到未来的日期我不想要过去的时间。我怎么能这样做?
答案 0 :(得分:0)
只需执行此操作,将其放入函数中并按下按钮即可运行。
<input type="date" id="date1" name="bday">
<script type="text/javascript">
var valDate = document.querySelector("date1");
var date = "";
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear();
if(dd<10) {
dd='0'+dd
}
if(mm<10) {
mm='0'+mm
}
today = mm+'/'+dd+'/'+yyyy;
today = today.split('/');
date = valDate.value.split('/');
if(parseInt(date)<parseInt(today)){
alert("please enter the date in the future or present not the past");
}
</script>