蒲蒲森
2017-03-28 12:48
时间间隔调成5000ms不是应该5秒执行一次clock函数吗,为什么显示还是每秒更新一次时间。那设置间隔有什么用
<!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,5000);
</script>
</head>
<body>
<form>
<input type="text" id="clock" size="50" />
</form>
</body>
</html>
我的更厉害,不设置时间还在跑
我的也是设置五秒执行后还是开始的一秒运行一次
测试先设置5000 5s运行一次
再设置1000 1s运行一次
再设置5000 5s运行一次
没毛病
测试后的确是5S更新一次时间.你再试试...
JavaScript进阶篇
469071 学习 · 22582 问题
相似问题