问答详情
源自:8-5 计时器setTimeout()

延迟1s

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>计时器</title>
</head>
<script type="text/javascript">
  var num=0;
  function startCount() {
    document.getElementById('count').value=num;
    num=num+1;
    setTimeout("startCount()",1000);
  }
    setTimeout("startCount()",0);
</script>
</head>
<body>
<form>
<input type="text" id="count" />
</form>
</body>
</html>


提问者:Alyssa_Lee 2014-12-10 14:48

个回答

  • 星空学者
    2015-12-25 14:53:28

    <!DOCTYPE HTML>

    <html>

    <head>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

    <title>计时器</title>

    </head>

    <script type="text/javascript">

      var num=0;

      function startCount() {

        document.getElementById('count').value=num;

        num=num+1;

        setTimeout("startCount()",500);

      }

        setTimeout("startCount()",500;

    </script>

    </head>

    <body>

    <form>

    <input type="text" id="count" />

    </form>

    </body>

    </html>