再加一个按钮star,点击按钮计时器继续运行怎么实现呢

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

慕哥2132778

2019-07-15 16:23

<!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 = setInterval(clock,1000);

</script>

</head>

<body>

<form>

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

<input type="button" value="start" onclick="setInterval(clock,1000)">

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

</form>

</body>

</html>


写回答 关注

4回答

  • qq_慕九州8416717
    2020-01-15 14:09:30

    没用的 重新开始根本触发不了  有没有大神


  • 慕运维6548256
    2019-09-02 13:31:30

    <!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=setInterval("clock()",1000);

       function begin(){

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

       }

        

    </script>

    </head>

    <body>

      <form>

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

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

        <input type="button" value="Begin" onclick="begin()" />

      </form>

    </body>

    </html>



  • linatz
    2019-07-20 10:18:13

    <!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=setInterval("clock()",100);
        function setTime(){
            var er=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="Begin" onclick="setTime()" />
      </form>
    </body>
    </html>

  • 代码里成长
    2019-07-17 17:13:46

    <input type="button" value="Begin" onclick="setInterval(i)" />

JavaScript进阶篇

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

468061 学习 · 21891 问题

查看课程

相似问题