function clock(){ var time=new Date(); var attime= time.getHours()+"-"+time.getMinutes()+"-"+time.getSeconds(); document.getElementById("clock").value = attime; }()
2 回答
刚毅87
TA贡献345条经验 获得超309个赞
你这代码缺少定时器吧
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title>> </head> <body> <input type="text" id="clock" /> </body> <script type="text/javascript"> function clock() { var time = new Date(); var attime = time.getHours() + "-" + time.getMinutes() + "-" + time.getSeconds(); document.getElementById("clock").value = attime; } setInterval(clock, 1000); </script> </html>
添加一个定时器,让函数一秒执行一次.
添加回答
举报
0/150
提交
取消