zoukankan      html  css  js  c++  java
  • setTimeout, setInterval

    代码
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    </head>

    <body>
    <h4>现在的时间为:<span id="a"></span></h4>

    <script type="text/javascript">
    showTime();
    function showTime(){
    var d = new Date();
    var a = document.getElementById("a");
    a.innerHTML
    = "This time " + d.toLocaleString();
    setTimeout(
    "showTime()", 1000);
    }
    </script>

    <h4>这里的内容是<span id="content"></span></h4>
    <input type="button" value="start" onclick="timer = setInterval('startShow()', 1000)" />
    <input type="button" value="stop" onclick="stopShow()" />
    <script type="text/javascript">
    var iValue = 1;
    //var timer = null;
    var cont = document.getElementById("content");
    //var timer = setInterval("startShow()", 1000);
    function startShow(){
    cont.innerHTML
    = cont.innerHTML + (iValue++) + " - ";
    //timer = setTimeout("startShow()", 1000);
    }
    function stopShow(){
    clearInterval(timer);
    }
    </script>

    </body>
    </html>
    通过这个小练习,掌握了setTimeout,setInterval的用法。

  • 相关阅读:
    git clone代码总是失败
    sublime常用快捷键及插件
    canvas圆形倒计时
    box-show的用法
    全选、反选
    数据库,增删改查
    PHP操作MySQL
    输出六个随机字符串
    约瑟夫环的故事
    Unix编程艺术——摘录一
  • 原文地址:https://www.cnblogs.com/jikey/p/1680617.html
Copyright © 2011-2022 走看看