html input type = date, field constraints

This question already has an answer here:

  • How do I get the current date in JavaScript? 39 answers

  • You would have to use JavaScript to get the current date and then parse some information from it. The code was taken from Samuel Meddows' accepted answer to the question How do I get the current date in JavaScript and then tweaked to work with the min attribute of the HTML input tag.

    var today = new Date();
    var dd = today.getDate();
    var mm = today.getMonth() + 1; //January is 0!
    var yyyy = today.getFullYear();
    
    if (dd < 10) {
      dd = '0' + dd
    }
    
    if (mm < 10) {
      mm = '0' + mm
    }
    
    today = yyyy + '-' + mm + '-' + dd;
    document.getElementById('input').setAttribute("min", today);
    Enter Payment Date : <input id="input" type="date" name="date" required><br/><br/>
    链接地址: http://www.djcxy.com/p/77524.html

    上一篇: jquery显示错误的日期

    下一篇: html输入类型=日期,字段限制