zoukankan      html  css  js  c++  java
  • js中定时器之一

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title></title>
    <script type="text/javascript">
    var id;
    function startInterval(){
    id = setInterval(function(){
    alert("interval evaling");
    },3000);
    }

    function testClear(){
    clearInterval(id);
    }

    function testCount(){
    var count = 0;
    var date;
    setInterval(function(){
    count++;
    //console.log(count);
    date = new Date();



    //document.getElementById("count").innerHTML = ""+count;
    document.getElementById("count").innerHTML = date.getFullYear()+"年"+(date.getMonth()+1)+"月"+date.getDate()+"日 "+date.getHours()+":"+date.getMinutes()+":"+date.getSeconds()+":"+date.getMilliseconds();
    },1)
    }

    /**
    *
    */

    </script>
    </head>
    <body>
    <input type="button" onclick="startInterval()" value="interval"/>
    <input type="button" onclick="testClear()" value="clear"/>
    <input type="button" onclick="testCount()" value="count">
    <div id="count" style="color: red;">
    0
    </div>
    </body>
    </html>
  • 相关阅读:
    反射&异常
    成员方法
    继承&多态
    面向对象
    常用模块
    软件目录结构规范
    内置函数
    生产器&迭代器
    装饰器
    函数
  • 原文地址:https://www.cnblogs.com/hwgok/p/5730311.html
Copyright © 2011-2022 走看看