date只能选择今天之后的时间js

Html

    <input type="date" id="time" min="2019-12-13" />

Js

    var date = new Date();
    var year = date.getFullYear();
    var month = ('0' + (date.getMonth() + 1)).slice(-2);
    var day = ('0' + (date.getDate())).slice(-2);
    var day1 = ('0' + (date.getDate() + 1)).slice(-2);
    var time = year + '-' + month + '-' + day;
    var time1 = year + '-' + month + '-' + day1;
    document.getElementById('time').value = time;
    //限制不能选择今天之后的日期(加上属性max)
    document.getElementById('time').setAttribute('min', time1);

猜你喜欢

转载自www.cnblogs.com/wulicute-TS/p/12034943.html