设置Input标签Date默认值为当前时间

时间:2024-07-01 14:36:14

需求:想设置Imput标签Date默认值为当前时间,通过JavaScript实现。

<html>

......

<body>

<input type="date" id="date_info" placeholder="请输入时间"/>

......

<script>
$(document).ready(function () {
var time = new Date();
var day = ("0" + time.getDate()).slice(-2);
var month = ("0" + (time.getMonth() + 1)).slice(-2);
var today = time.getFullYear() + "-" + (month) + "-" + (day);
$('#date_info').val(today);
})
</script> </body> </html>

---------------------
作者:Mf是个大坏蛋
来源:****
原文:https://blog.****.net/destinymf/article/details/81135400