简体   繁体   中英

How can I set Max date to 7th day from today in input type date?

var today = new Date().toISOString().split('T')[0];

document.getElementsByName("DateOfTravel")[0].setAttribute('min', today);

With the help of this I am able to set min date to today date but now I want to set max date to 7th date from today's date

You can write following code.

<input type="date" id="datePickerId" />

var date = new Date();
date.setDate(date.getDate() + 7);

datePickerId.max = date.toISOString().split("T")[0];

Try this:

var date = new Date();
date.setDate(date.getDate() + 7);
var today = date.toISOString().split('T')[0];
document.getElementsByName("DateOfTravel")[0].setAttribute('max', today);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM