将当前时间日期写入文本框
分类:实例代码
分享一个极为简单的代码实例,它能够将当前系统的时间日期写入文本框。
代码实例如下:
<!doctype html> <html> <head> <meta charset="utf-8"> <meta name="author" content="http://www.pipipi.net/" /> <title>犀牛前端部落</title> <script type="text/javascript"> function today() { var today = new Date(); var h = today.getFullYear(); var m = today.getMonth() + 1; var d = today.getDate(); var H = today.getHours(); var M = today.getMinutes(); var S = today.getSeconds(); return h + "-" + m + "-" + d + " " + H + ":" + M + ":" + S; } window.onload = function () { var otxt = document.getElementById("time") otxt.value = today(); } </script> </head> <body> <input type="text" id="time"/> </body> </html>
上面的代码极为简单,更多相关内容可以参阅JavaScript Date对象一章节。
将当前时间日期写入文本框,这样的场景在实际项目中还是用的比较多的,关于将当前时间日期写入文本框就介绍到这了。
将当前时间日期写入文本框属于前端实例代码,有关更多实例代码大家可以查看。
