我试过了(JSFiddle):

<input type="date" value="2012-3-23"> .

但它不起作用,我如何设置默认值?


当前回答

<input type=“date” id=“myDate” />

然后在js中:

_today: function () {
  var myDate = document.querySelector(myDate);
  var today = new Date();
  myDate.value = today.toISOString().substr(0, 10);
},

其他回答

一个可能的解决方案:

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

使用Moment.js:

var today = moment().format('YYYY-MM-DD');
document.getElementById("datePicker").value = today;

您可以简单地按照正确的格式显示日期

<input type="date" value="2014-12-29">

你可以这样做:

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

<input type=“date” id=“myDate” />

然后在js中:

_today: function () {
  var myDate = document.querySelector(myDate);
  var today = new Date();
  myDate.value = today.toISOString().substr(0, 10);
},
$date=date("Y-m-d");
echo"$date";
echo"<br>SELECT DATE: <input type='date'  name='date'  id='datepicker' 
value='$date' required >";