给input添加max属性, 值为日期
<script>
//input date 限制选择的时间,只能选择之后的时间
$(function () {
//得到明天时间
const t = new Date(new Date().getTime() + 86400000);
//得到当前年份
var year = t.getFullYear();
//得到当前月份
//注:
// 1:js中获取Date中的month时,会比当前月份少一个月,所以这里需要先加一
// 2: 判断当前月份是否小于10,如果小于,那么就在月份的前面加一个 '0' , 如果大于,就显示当前月份
var month = t.getMonth() + 1 < 10 ? "0" + (t.getMonth() + 1) : (t.getMonth() + 1);
// 明天多少号
const torr = t.getDate() < 10 ? "0" + t.getDate() : t.getDate();
//设置input标签的min属性 从明天选择之后的日期,max最大,只能选择之前的日期
$("#time").attr("min", year + "-" + month + "-" + torr);
})
</script>
<input type="date" name="date" id="time">