问答详情
源自:8-3 计时器setInterval()

我写的代码是否正确?

<!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;

    document.getElementById("clock").value = attime;

  }

  var attime=setInterval(clock,100)

</script>

</head>

<body>

<form>

<input type="text" id="clock" size="50"  />

</form>

</body>

</html>


提问者:荣耀zyy 2016-07-21 10:17

个回答

  • qq_韶轩寂雪_03557907
    2016-07-21 11:38:18
    已采纳

    attime=time.getHours()+":"+time.getMinutes()+":"+time.getSeconds();

    这样看着好看些

  • 696216
    2016-07-21 11:54:37

    可以运行

  • qq_岂能尽如人意但求无愧于心_0
    2016-07-21 11:09:47

    能运行就对啊