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

后端 未结 30 3481
刺人心
刺人心 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:16

    by Javascript:

    var today = new Date();
    
    document.getElementById("theDate").value = today.getFullYear() + '-' + ('0' + (today.getMonth() + 1)).slice(-2) + '-' + ('0' + today.getDate()).slice(-2);
    

提交回复
热议问题