解决方案 »

  1.   


    <html>
         <head>
             <title>6-9</title>
             <script type="text/javascript">
                 var c = 0;
                 var t;
                 function timedCount() {
                     document.getElementById('txt').value=c;
                     c = c+1;
                     t = setTimeout("timedCount()", 1000);
                 }
                 function startCount() {
                     c=document.getElementById('txt').value*1;
                     timedCount();
     }
                 function stopCount() {
                     clearTimeout(t);
                 }
             </script>
         </head>
         <body>
             <form>
                 <input type="button" value="开始计时!" onclick="startCount()">
                 <input type="text" id="txt" value="0">
                 <input type="button" value="停止计时!" onclick="stopCount()">
             </form>
             <p>请点击上面的“开始计时”按钮。输入框会从 0 开始一直进行计时。点击“停止计时”可停止计时。</p>
         </body>
     </html>
      

  2.   

    谢谢,功能实现了。
    有一个小BUG,就是多按几次”开始计时“的话,停止和时间的跳动也会变化。请问怎么解决?
      

  3.   

    借用楼上的
    <html>
         <head>
             <title>6-9</title>
             <script type="text/javascript">
                 var c = 0;
                 var t;
                 function timedCount() {
                     document.getElementById('txt').value=c;
                     c = c+1;
                     t = setTimeout("timedCount()", 1000);
                 }
                 function startCount() {
                   if(t){alert(111);return;}
                     c=document.getElementById('txt').value*1;
                     timedCount();
                 }
                 function stopCount() {
                     clearTimeout(t);
                   t=0;
                 }
             </script>
         </head>
         <body>
             <form>
                 <input type="button" value="开始计时!" onclick="startCount()">
                 <input type="text" id="txt" value="0">
                 <input type="button" value="停止计时!" onclick="stopCount()">
             </form>
             <p>请点击上面的“开始计时”按钮。输入框会从 0 开始一直进行计时。点击“停止计时”可停止计时。</p>
         </body>
     </html>
      

  4.   

    借用楼上的
    <html>
         <head>
             <title>6-9</title>
             <script type="text/javascript">
                 var c = 0;
                 var t;
                 function timedCount() {
                     document.getElementById('txt').value=c;
                     c = c+1;
                     t = setTimeout("timedCount()", 1000);
                 }
                 function startCount() {
                   if(t){alert(111);return;}
                     c=document.getElementById('txt').value*1;
                     timedCount();
                 }
                 function stopCount() {
                     clearTimeout(t);
                   t=0;
                 }
             </script>
         </head>
         <body>
             <form>
                 <input type="button" value="开始计时!" onclick="startCount()">
                 <input type="text" id="txt" value="0">
                 <input type="button" value="停止计时!" onclick="stopCount()">
             </form>
             <p>请点击上面的“开始计时”按钮。输入框会从 0 开始一直进行计时。点击“停止计时”可停止计时。</p>
         </body>
     </html>
    这一句的意思是什么啊?“”if(t){alert(111);return;}“”,是t为ture就返回什么吗?否则返回什么?
    我不太看的懂刚学
      

  5.   

    借用楼上的
    <html>
         <head>
             <title>6-9</title>
             <script type="text/javascript">
                 var c = 0;
                 var t;
                 function timedCount() {
                     document.getElementById('txt').value=c;
                     c = c+1;
                     t = setTimeout("timedCount()", 1000);
                 }
                 function startCount() {
                   if(t){alert(111);return;}
                     c=document.getElementById('txt').value*1;
                     timedCount();
                 }
                 function stopCount() {
                     clearTimeout(t);
                   t=0;
                 }
             </script>
         </head>
         <body>
             <form>
                 <input type="button" value="开始计时!" onclick="startCount()">
                 <input type="text" id="txt" value="0">
                 <input type="button" value="停止计时!" onclick="stopCount()">
             </form>
             <p>请点击上面的“开始计时”按钮。输入框会从 0 开始一直进行计时。点击“停止计时”可停止计时。</p>
         </body>
     </html>
    这一句的意思是什么啊?“”if(t){alert(111);return;}“”,是t为ture就返回什么吗?否则返回什么?
    我不太看的懂刚学
    如果t不等于0即表示在计时就返回,否则计时
      

  6.   

    借用楼上的
    <html>
         <head>
             <title>6-9</title>
             <script type="text/javascript">
                 var c = 0;
                 var t;
                 function timedCount() {
                     document.getElementById('txt').value=c;
                     c = c+1;
                     t = setTimeout("timedCount()", 1000);
                 }
                 function startCount() {
                   if(t){alert(111);return;}
                     c=document.getElementById('txt').value*1;
                     timedCount();
                 }
                 function stopCount() {
                     clearTimeout(t);
                   t=0;
                 }
             </script>
         </head>
         <body>
             <form>
                 <input type="button" value="开始计时!" onclick="startCount()">
                 <input type="text" id="txt" value="0">
                 <input type="button" value="停止计时!" onclick="stopCount()">
             </form>
             <p>请点击上面的“开始计时”按钮。输入框会从 0 开始一直进行计时。点击“停止计时”可停止计时。</p>
         </body>
     </html>
    这一句的意思是什么啊?“”if(t){alert(111);return;}“”,是t为ture就返回什么吗?否则返回什么?
    我不太看的懂刚学
    如果t不等于0即表示在计时就返回,否则计时
    谢谢,我懂了