[英]How to increment date and how to disable previous dates in javascript?
Im using html5 datepicker like [input type="date"],我使用 html5 日期选择器,如 [input type="date"],
I just need to increment current date + 1. i mean show the tomorrow date and future dates only, the current date and previous dates wants to go disable state only show the future dates..我只需要增加当前日期 + 1。我的意思是只显示明天的日期和未来的日期,当前日期和以前的日期想要禁用状态只显示未来的日期..
anyone please help me..任何人请帮助我..
here is my tried code.这是我尝试过的代码。
// Disable date var input = document.getElementById("preDate"); var today = new Date(); var day = today.getDate()+1; var mon = new String(today.getMonth()+1); //January is 0! var yr = today.getFullYear(); if (mon.length < 0) { mon = "0" + mon; } var date = new String(yr + '-' + mon + '-' + day); input.disabled = false; input.setAttribute('min', date);
<div class="form-group col-3 rfdate"> <label class="col-sm-6 control-label p-sm-0">Refund Date</label> <input type="date" class="form-control" id="preDate" name="preDate" /> </div>
Fiddle: Code Here..小提琴:代码在这里..
Try this:尝试这个:
// Disable date var input = document.getElementById("preDate"); var today = new Date(); var day = today.getDate()+1; var mon = new String(today.getMonth()+1); //January is 0! var yr = today.getFullYear(); if (mon.length > 0) { mon = `0${mon}`; } if (day < 10) { day = `0${day}`; } var date = `${yr}-${mon}-${day}`; input.disabled = false; input.setAttribute('min', date); input.value = date; console.log(date);
<div class="form-group col-3 rfdate"> <label class="col-sm-6 control-label p-sm-0">Refund Date</label> <input type="date" class="form-control" id="preDate" name="preDate" /> </div>
Tomorrows date is smart created like that:明天的日期是这样智能创建的:
var tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate() + 1);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.