type=‘datetime-local’的input是h5中一种新的日历标签,它包括年月日时分。现在项目中的需求为每次打开让他默认为当前的日期,但是时分需要是归零。样式为: 2018/11/19 00:00
代码为:
<body>
<label>
<span>测量日期</span>
<input type="datetime-local" class="measureDate" placeholder="请输入测量日期">
</label>
<script type="text/javascript" src='jquery.js'></script>
<script type="text/javascript">
//希望每次打开都要默认为今天日期+00:00
//默认时间
var myDate = new Date(), Y = myDate.getFullYear(), M = myDate.getMonth() + 1, D = myDate.getDate();
//处理月是一位的情况
if((M + '').length == 1){
M = '0' + (M + '');
}
//处理日是一位的情况
if((D + '').length == 1){
D = '0' + (D + '')
}
var curDay = Y + '-' + M + '-' + D;
console.log(curDay)
$('.measureDate').val(curDay + 'T00:00')
</script>
</body>