JS定时器_setInterval

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

 

1、

window.setInterval(A, B);

window.clearInterval(?);

 

2、

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

 

3、简单例子:

    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 + ""); }

 

4、

5、

6、

 

posted @ 2016-03-15 21:58  Html5Skill  阅读(472)  评论(0编辑  收藏  举报