设置规定时间后进行跳转

Posted on 2022-03-16 13:59  君子不卿  阅读(37)  评论(0编辑  收藏  举报
<body>
<h1>页面将在 <span style="font-size: 30px;color: red"> <span id="n">5 </span></span>秒钟后跳转</h1>
<script>
    var timer = setInterval(show,1000);
    var n = 5;
    function show(){
        // console.log(Math.random());
        if(n>0){
            n--;
            document.getElementById("n").innerText = n;
        }else{
            clearInterval(timer);
            location.href = "http://www.baidu.com";
        }
        // console.log(Math.random());
    }
    // setTimeout(f,5000);
    // function f() {
    //     location.href = "http://www.baidu.com";
    // }
</script>
</body>

 

Copyright © 2025 君子不卿
Powered by .NET 9.0 on Kubernetes

//评论