体验定时器

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<script>

    //setInterval();   setTimeout();
//    var num = 0;
//    setInterval(function () {
//        console.log(num);
//        num++;
//    },1000);


    //用途:setInterval()循环定时器;周而复始的执行(循环执行)
    //用途:setTimeout() 炸弹定时器;用完以后立刻报废(只执行一次)


    //定义方法1(匿名函数)
//    setInterval(function () {
//        console.log(1);
//    },1000);


//    //定义方法2
//    setInterval(fn,1000);
//    function fn(){
//        console.log(2);
//    }

    //定义方法3
//    setInterval("fn(3)",1000);
//    function fn(aaa){
//        console.log(aaa);
//    }

</script>
</body>
</html>

猜你喜欢

转载自blog.csdn.net/sky6even/article/details/80767948