zoukankan      html  css  js  c++  java
  • js中setTimeout和clearTimeout的使用

    setTimeout,延迟n秒后执行指定代码

    clearTimeout,清除计时器

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

    参考:

    https://blog.csdn.net/ainuser/article/details/78882473

  • 相关阅读:
    IndexDB
    实现es6中的set和map
    视口viewport
    nginx入门
    http协议
    图像格式
    promise
    js中this指向
    CSS 7阶层叠水平
    C# 一个方法如何返回多个值
  • 原文地址:https://www.cnblogs.com/sea-stream/p/10449186.html
Copyright © 2011-2022 走看看