qq_猫小懒_0
2018-03-26 10:58
截图中是我改的,运行之后输入框中没有任何东西。不知道问题出在哪里,应该怎么改。求帮助
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>定时器</title>
<script type="text/javascript">
function count(){
var attime;
var time=new Date();
attime= time.getHours()+":"+add0(time.getMinutes()) +":"+add0(time.getSeconds());
document.getElementById("clock").value = attime;
setTimeout("count()",500);
}
setTimeout("count()",500);
function add0(num){
return (num<10)? "0"+num : num;
}
</script>
</head>
<body>
<form>
<input type="text" id="clock" size="50" />
</form>
</body>
</html>
*************************
备注:
1,定时器得设置,才能运行;
2,考虑到“分”和“秒”的数字小于10的时候,于前面加个“0”比较美观,于是,另外定义一个add0函数。
<!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>
你的没有设置定时器啊
JavaScript进阶篇
468060 学习 · 21891 问题
相似问题
回答 1
回答 1