给定一个输入元素:
<input type="date" />
有没有办法将日期字段的默认值设置为今天的日期?
给定一个输入元素:
<input type="date" />
有没有办法将日期字段的默认值设置为今天的日期?
当前回答
来匹配原始查询。
date.value = new Date().toJSON().split('T')[0] <输入类型=“日期” id=“日期”/>
其他回答
来匹配原始查询。
date.value = new Date().toJSON().split('T')[0] <输入类型=“日期” id=“日期”/>
对于那些使用ASP VBScript的人
<%
'Generates date in yyyy-mm-dd format
Function GetFormattedDate(setDate)
strDate = CDate(setDate)
strDay = DatePart("d", strDate)
strMonth = DatePart("m", strDate)
strYear = DatePart("yyyy", strDate)
If strDay < 10 Then
strDay = "0" & strDay
End If
If strMonth < 10 Then
strMonth = "0" & strMonth
End If
GetFormattedDate = strYear & "-" & strMonth & "-" & strDay
End Function
%>
然后在body中,元素应该是这样的
<input name="today" type="date" value="<%= GetFormattedDate(now) %>" />
干杯!
这依赖于PHP:
<input type="date" value="<?php echo date('Y-m-d'); ?>" />
这是非常简单的应用下面的代码,使用PHP
<input type="date" value="<?= date('Y-m-d', time()); ?>" />
Date函数将通过Date in time()返回当前日期。
$(document).ready(function(){
var date = new Date();
var day = ("0" + date.getDate()).slice(-2); var month = ("0" + (date.getMonth() + 1)).slice(-2);
var today = date.getFullYear()+"-"+(month)+"-"+(day) ;
});
$('#dateid').val(today);