How to set input type date's default value to today?

后端 未结 30 3024
刺人心
刺人心 2020-11-22 14:00

The HTML5 input types are great, Opera\'s new built-in date picker is a breeze, and Chrome has at least supported the new input type with a spin-wheel implementation.

<
30条回答
  •  死守一世寂寞
    2020-11-22 14:13

    use moment.js to solve this issue in 2 lines, html5 date input type only accept "YYYY-MM-DD" this format. I solve my problem this way.

    var today = moment().format('YYYY-MM-DD');
     $('#datePicker').val(today);
    

    this is simplest way to solve this issue.

提交回复
热议问题