简体   繁体   中英

Disable back date entries in input type 'date'

I am using input type date in my project instead of datepicker. I want to restrict back dates from current date in input type date. I know about how to restrict back dates in datepicker but i dont want to use it.

Hence Please suggest is it possible to restrict back dates in input type date (html).

更改Javascript中输入的最小值,如下所示:

    document.getElementById("myDate").min = "2017-03-16";

Try this

var inputMyDate = document.querySelector('input#finaldate');

inputMyDate.addEventListener('input', function() {  
    var current = this.value;               
    var today = new Date();     
    var dd = today.getDate();       
    var mm = today.getMonth()+1;
    var yyyy = today.getFullYear();
    if(dd<10){
        dd='0'+dd;
    } 
    if(mm<10){
        mm='0'+mm;
    } 
    var today = yyyy+'-'+mm+'-'+dd;                     
    if (current < today){
        document.getElementById('finaldate').value = 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