zoukankan      html  css  js  c++  java
  • js简版定时器

     1 <html>
     2 <head>
     3 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
     4 <title>定时器</title>
     5 <style type='text/css'>
     6 #box {width:80px; height:80px; background:#f00; position:absolute; left:50px; top:50px;}
     7 </style>
     8 <script>
     9        var $time;
    10          function $(id){
    11              return document.getElementById(id);
    12           }
    13           function start(){
    14              $("span").innerHTML=parseInt($("span").innerHTML)+1;
    15              $time=setTimeout('start()',1000);
    16           }
    17     window.onload = function() {
    18          $("start").onclick=function(){
    19                 start();
    20              }
    21              $("end").onclick=function(){
    22                //取消定时器
    23                 clearTimeout($time);
    24                 $("span").innerHTML=1;
    25              }
    26       }
    27 </script>
    28 </head>
    29 <body>
    30 <span id="span">1</span><br/>
    31 <input type="button" id="start" value="开始" /><br/>
    32 <input type="button" id="end" value="结束" /><br/>
    33 </body>
    34 </html>

    为制作动态时间程序作基础

  • 相关阅读:
    noip2015运输计划
    bzoj3595 方伯伯的oj
    noip模拟赛 #3
    圆方树
    AtCoder AGC #4 Virtual Participation
    noip模拟赛 #2
    AtCoder AGC #3 Virtual Participation
    UNR #1 火车管理
    noip模拟赛
    AtCoder AGC #2 Virtual Participation
  • 原文地址:https://www.cnblogs.com/tmrgd/p/5787715.html
Copyright © 2011-2022 走看看