首页 > 代码库 > js倒计时+页面跳转

js倒计时+页面跳转

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    //    5秒倒计时跳转
    var num_s = 5;
    var cal_timer = setInterval(showTime, 5000);
    function showTime() {
        num_s--;
        if (num_s == 0) {
            window.location = "index.html";
            clearTimeout(cal_timer)
        }

        console.log(num_s)
    }
</script>
</body>
</html>

 

 

倒计时页面跳转,meta标签

 <!--5秒钟后跳转到指定的页面-->
    <meta http-equiv="refresh" content="5;url=http://www.baidu.com" />

 

单位换算:

1秒=1000毫秒

js倒计时+页面跳转