简体   繁体   中英

input date javascript html (min and max)

how to set min date as current date in date picker and max date as 30 days after current date? its for a booking form. I searched everywhere couldn't find any solution.

It's as simple as:

 const d = new Date(); const min = d.toISOString().split("T")[0] date.min = min; var max = d; max.setDate(d.getDate() + 30) date.max = max.toISOString().split("T")[0]
 <input type="date" id="date">

Simply like that:

 let input = document.getElementById("input") input.min = new Date().toISOString().split('T')[0] input.max = new Date(new Date()+2592000000).toISOString().split('T')[0]
 <input type="date" id="input">

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