递归调用

<script>
    //获取id,倒数值,速度,设定定时器,函数,倒数值减,页面文字,如果小于倒数值,页面跳转;大于,不跳转,继续执行;
    vardemo = document.getElementById("demo");
    varcount = 5;
    varspeed = 1000;
    setTimeout(Index,speed);
    functionIndex(){
        count--;
        demo.innerHTML= "页面将在"+count+"秒钟后跳转到首页";
        if(count <= 0){
            window.location.href= "http://www.baidu.com";
        }else{
            setTimeout(Index,speed);  // 递归调用,自己调用自己;
        }
    }
script>

你可能感兴趣的:(效果)