我无法在 JS 的输入框中设置当前日期。
我试过下面的代码,但它仍然默认为“MM/DD/YYYY”作为占位符。
如何将日期设置为当前日期?
HTML:
<label>Start Date:</label>
<input type="date" id="dteStartDate">
JavaScript:
var currdate = new Date();
var currdate = (currdate.getMonth() + 1) + '/' +
currdate.getDate() + '/' +
currdate.getFullYear();
$('#dteStartDate').datetimepicker({dateFormat: 'mm-dd-yy'})
.datetimepicker("setDate", currdate);
最佳答案
尝试
$('#dteStartDate').datetimepicker({dateFormat: 'mm-dd-yy'})
.datetimepicker("setDate", new Date());
无需转成字符串
关于javascript - 试图在 JS 输入框中获取今天的日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29757869/