How to set default value to the input[type="date"]

I have tried

<input type="date" value="2013-1-8">

like this: demo

but I failed, how can I set the default value?


The date should take the format YYYY-MM-DD . Single digit days and months should be padded with a 0. January is 01.

From the documentation:

A string representing a date.

Value: A valid full-date as defined in [RFC 3339], with the additional qualification that the year component is four or more digits representing a number greater than 0.

Your code should be altered to

<input type="date" value="2013-01-08">

Example jsfiddle


if you are using PHP, you can set the value like this

<input type="date" value="<?php echo date("Y-m-d");?>">

but remember that it would return the date of the server. if you want to use from the client, use javascript instead. hope it helps.


A possible solution

document.getElementById("yourDatePicker").valueAsDate = new Date()

using Moment.js

var today = moment().format('YYYY-MM-DD');
document.getElementById("datePicker").value = today; 
链接地址: http://www.djcxy.com/p/18650.html

上一篇: 有没有办法改变输入类型=“日期”格式?

下一篇: 如何设置默认值到输入[type =“date”]