The current date is automatically displayed in the input box

Home  >  Article  >  Web Front-end  >  How can I display the current date in the input box?

How can I display the current date in the input box?

零下一度
零下一度Original
2017-07-19 17:48:031556browse

Go directly to the code:

<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>input框中自动展示当前日期</title>
</head><body><input type="text" id="input"><script>
//获取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(&#39;disabled&#39;, &#39;disabled&#39;);
     //不可编辑</script></body></html>

Note here that the getMonth() method uses local time. The return value is an integer between 0 (January) and 11 (December).

The above is the detailed content of How can I display the current date in the input box?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn