How do I restrict past dates in html5 input type Date

前端 未结 7 2122
天命终不由人
天命终不由人 2020-12-10 16:40

I am trying to restrict past dates in input type=\"date\".I can able to restrict future dates,But I don\'t have idea about restricting past dates.

7条回答
  •  [愿得一人]
    2020-12-10 17:34

    In HTML:

    
    

    Using Jquery new version:

    function SetMinDate() {
        var now = new Date();
    
        var day = ("0" + now.getDate()).slice(-2);
        var month = ("0" + (now.getMonth() + 1)).slice(-2);
    
        var today = now.getFullYear() + "-" + (month) + "-" + (day);
    
        $('#ExpiryDate').val(today);
        $('#ExpiryDate').attr('min', today); }
    

提交回复
热议问题