鄙人不才,继续暂停,继续暂停

来源:8-4 取消计时器clearInterval()

黑夜的白_羊

2020-06-08 22:40

<!DOCTYPE HTML>

<html>

    <head>

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

        <title>计时器</title>

        <script type="text/javascript">

           function clock(){

                 var time=new Date();

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

           }

           var i;

           function start() {   

             i = setInterval("clock()",100);

           }

           i=setInterval("clock()",100);

        </script>

    </head>

    <body>

      <form>

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

          <input type="button" value="Stop" onclick="clearInterval(i)" />

          <input type="button" value="Start" onclick="start()" />

          

      </form>

    </body>

</html>


写回答 关注

3回答

  • qq_慕田峪3498577
    2020-10-16 14:51:42

    <!DOCTYPE HTML>

    <html>

    <head>

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

    <title>计时器</title>

    <script type="text/javascript">

       var  s=false;

       function clock(){

          var time=new Date();                  

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

       }

         var i=setInterval(clock,1000);

         function fc()

         {

             if(s)

             {

                 s=false;

                 i=setInterval(clock,1000)

             }else

             {

                 s=true;

                 clearInterval(i);

             }

         }

    </script>

    </head>

    <body>

      <form>

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

        <input type="button" value="Stop" onclick="fc()" />


      </form>

    </body>

    </html>


  • Weiss3858599
    2020-08-15 09:57:20

    再点停止就失效了

  • 黑夜的白_羊
    2020-06-08 22:42:00

    看到有好多人问继续暂停继续暂停怎么搞,就这么搞吧,马马虎虎

JavaScript进阶篇

本课程从如何插入JS代码开始,带您进入网页动态交互世界

467404 学习 · 21877 问题

查看课程

相似问题