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

哪位大神看看为什么运行不了

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

提问者:qq_Sinkingsmile_1 2018-07-15 17:44

个回答

  • 造物主学徒
    2018-08-03 16:37:27

    <input type="text" id="count" />加个onClick="startCount()" 

  • 造物主学徒
    2018-08-03 16:35:43

    <!DOCTYPE HTML>

    <html>

    <head>

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

    <title>计时器</title>

    <script type="text/javascript">

      var num=0;

      function startCount() {

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

        num=num+1;

        setTimeout("startCount()",1000);

      }

      

    </script>

    </head>

    <body>

    <form>

    <input type="text" id="count" onClick="startCount()" />

    </form>

    </body>

    </html>


  • DaveTang
    2018-07-15 21:03:20

    <!DOCTYPE html>
    <html>    
     <head>        
      <title></title>        
      <meta charset="UTF-8">    
     </head>    
     <body>        
     <div id="count"></div>         
     <script>                 
     window.onload = showTime;                        
     var show = document.getElementById('count');                        
     function showTime() {                                
       var date = new Date();                
       let h = date.getHours();                
       let m = date.getMinutes();                
       let s = date.getSeconds();               
       m = checkTime(m);                
       s = checkTime(s);                
       show.innerHTML = h + ':' + m + ':' + s;                                
       t = setTimeout(function () {                    
         showTime();                
       }, 1000);            
     }            
     function checkTime(i) {                 
        if (i < 10) {                    
         i = '0' + i;                
        }                
        return i;            
      }        
      </script>    
      </body>
    </html>