JS定时器_setInterval

ZC:setInterval 为自动重复,setTimeout 不会重复。spa

 

一、.net

window.setInterval(A, B);code

window.clearInterval(?);htm

 

二、blog

http://www.jb51.net/article/47819.htmget

 

三、简单例子:io

    var g_timer01 = null;

    function BtnClick03()
    {
        // setInterval 为自动重复,setTimeout 不会重复。
        g_timer01 = window.setInterval(TimerFunc01, 20);// ZC: 貌似 写成 setInterval("TimerFunc01()", 20); 也是能够的
        //window.clearInterval(g_timer01);//去掉定时器
} var g_iX_test01 = 100;// 与id为"test01"的矩形 的 属性"x" 的值相同 function TimerFunc01() { g_iX_test01 ++; //console.log("g_iX_test01 : "+g_iX_test01); if (g_iX_test01 >= 200) { window.clearInterval(g_timer01); console.log("g_timer01 is cleared ."); return; } var test01 = document.getElementById("test01"); test01.setAttribute("x", g_iX_test01 + ""); }

 

四、console

五、function

六、class

相关文章
相关标签/搜索