直接上代码:
<Meta charset="UTF-8">
input框中自动展示当前日期
//获取input元素
var _input = document.getElementById('input');
var date = new Date();
var seperator = "/";
var year = date.getFullYear();
var month = date.getMonth() + 1;
var strDate = date.getDate();
if (month >= 1 && month <= 9) {
month = "0" + month;
}
if (strDate >= 0 && strDate <= 9) {
strDate = "0" + strDate;
}
var currentDate = year + seperator + month + seperator + strDate; //当前日期
_input.value = currentDate; //赋值给input.value
_input.setAttribute('disabled','disabled'); //不可编辑