<!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>定时器</title><script type="text/javascript"> var attime; function clock(){ var time=new Date(); attime=time.getHours()+":"+time.getMinutes()+":"+time.getSeconds(); document.getElementById("clock").value = attime; } //setInterval(clock,100);</script></head><body><form><input type="text" id="clock" size="50" /></form></body></html>
1 回答
__innocence
TA贡献313条经验 获得超208个赞
两个错误:1.js写在文档前面,这样加载js的时候,输入框还没有加载,这样会造成错误
2、function clock只有声明,没有调用
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>定时器</title>
</head>
<body>
<form>
<input type="text" id="clock" size="50" />
</form>
<script type="text/javascript">
var attime;
function clock() {
var time = new Date();
attime = time.getHours() + ":" + time.getMinutes() + ":" + time.getSeconds();
document.getElementById("clock").value = attime;
}
clock();
//setInterval(clock,100);
</script>
</body>
</html>添加回答
举报
0/150
提交
取消
