zoukankan      html  css  js  c++  java
  • js定时器和计时器

    setTimeout定时器
    setInterver计时器



    用以指定在一段特定的时间后执行某段程序。
    •setTimeout():
    •格式: [定时器对象名=] setTimeout(“<表达式>”,毫秒) 功能:执行<表达式>一次

    <script type="text/javascript">
     
     function count()
     {
      setTimeout("alert('执行成功');", 7000);
     }
     
     </script>

      </head>
     
      <body>
       
        <input type="button" value="计时开始" onclick="count();">
       
      </body>

    setInterval():
    •格式: [定时器对象名=] setInterval(“<表达式>”,毫秒) 功能:重复执行<表达式>,直至窗口、框架被关闭或执行clearInterval。
    •clearInterval():终止定时器
    •格式: clearInterval(定时器对象名)

    <script type="text/javascript">
     
     var sec = 0;
     var timeId = setInterval("count();", 1000);
     
     function count()
     {
      document.getElementById("num").innerHTML = sec++;
     }
     
     function stopCount()
     {
      clearInterval(timeId);
     }
     
     </script>

      </head>
     
      <body>
       
        <font color="red" id="num">0</font>秒钟
       
        <input type="button" value="停止" onclick="stopCount();">

  • 相关阅读:
    1697 ⑨要写信
    1220 数字三角形
    4979 数塔
    bzoj1618[Usaco2008 Nov]Buying Hay 购买干草
    bzoj1066[SCOI2007]蜥蜴
    bzoj1008[HNOI2008]越狱
    cf437D The Child and Zoo
    cf437C The Child and Toy
    cf437B The Child and Set
    cf437A The Child and Homework
  • 原文地址:https://www.cnblogs.com/qiuh/p/3039579.html
Copyright © 2011-2022 走看看