星空网 > 软件开发 > Java

setTimeout、clearTimeout、setInterval,clearInterval ——小小计时器

先看下效果

setTimeout、clearTimeout、setInterval,clearInterval  ——小小计时器

 

话不多说上代码~

<!DOCTYPE HTML><html>  <head>    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">    <title>计时器</title>    <script type="text/javascript">      var num=0;      var i;      function clockstart(){         document.getElementById('clock').value=num;         num++;         i=setTimeout("clockstart()",1000);      }      function clockstop(){        clearTimeout(i);      }        function clockclear(){        num=0;        setTimeout("document.getElementById('clock').value=0",0);        clearTimeout(i);      }      </script>  </head>  <body>    <input type="text" id="clock" /><br/><br/>    <input type="button" value="开始" onclick="clockstart()" />    <input type="button" value="停止" onclick="clockstop()" />    <input type="button" value="复位" onclick="clockclear()" />  </body></html

 setTimeout、clearTimeout、setInterval,clearInterval  ——小小计时器

代码

<!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();      var attime=time.getHours()+":"+time.getMinutes()+":"+time.getSeconds();      document.getElementById('clock').value=attime;    }    setInterval("clock()",100);    </script>  </head>  <body>    <input type="text" id="clock" />  </body></html>

 




原标题:setTimeout、clearTimeout、setInterval,clearInterval ——小小计时器

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

马来西亚有什么物流:https://www.goluckyvip.com/tag/91606.html
烟可以寄到马来西亚吗:https://www.goluckyvip.com/tag/91607.html
可以邮寄到马来西亚吗:https://www.goluckyvip.com/tag/91608.html
国内包裹寄到马来西亚邮费怎么算:https://www.goluckyvip.com/tag/91609.html
运营思路:https://www.goluckyvip.com/tag/9161.html
什么快运可以寄到马来西亚:https://www.goluckyvip.com/tag/91610.html
国家博物馆清明节需要预约吗?:https://www.vstour.cn/a/362189.html
中国国家博物馆2024年清明假期开放公告:https://www.vstour.cn/a/362190.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流