JavaScript

setTimeout & setInterval

2017-11-09  本文已影响35人  sylvia_yue

setTimeout(function,time)——定时器,定时器超时时执行代码。
clearTimeout(function,time)——取消setTimeout()。
setInterval(function,time)——设置一个自动重复的定时器,每次超过指定时间,执行一次。
clearInterval(function,time)——取消setInterval()。
eg:

无参:
    function hello() {
        console.log(`hello`);
    }
    window.setInterval(hello,1000);
有参:
    function hello(_name){
        return function(){
            alert("hello,"+_name);    }
    }
    window.setTimeout(hello('sylvia'),3000);
上一篇 下一篇

猜你喜欢

热点阅读