How can i set today date as a default date in html
This question already has an answer here:
input type="date"
值始终为YYYY-MM-DD格式:
<input type="date" value="<?php print(date("Y-m-d")); ?>"/>
Like any HTML input field, the browser will leave it empty unless a default value is specified with the value attribute. HTML5 doesn't provide a way of specifying 'today' in the value.
You can do it with javascript or php.
Here is a sample with PHP :
<input type="date" id="myDate" value="<?php echo date('Y-m-d');?>"/>
Here is a sample with Javascript :
document.getElementById('myDate').value = new Date().toJSON().slice(0,10);
Here is a sample with jquery :
$(document).ready( function() {
$('#myDate').val(new Date().toJSON().slice(0,10));
});
链接地址: http://www.djcxy.com/p/18662.html
上一篇: 输入类型日期格式和日期选择器问题