简单定时器的使用

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
    window.onload = function(){
        var time = 5;
        var secondEle = document.getElementById("second");
        var timer = setInterval(function(){
            secondEle.innerHTML = time;
            time--;
            if(time==0){
                clearInterval(timer);
                location.href = "http://www.baidu.com";
            }
        },1000);
    }
</script>
</head>
<body>
    恭喜你,注册成功。<span style="color:red" id="second">5</span>秒内如不跳转点击<a href="www.baidu.com">百度</a>
</body>
</html>
原文地址:https://www.cnblogs.com/ms-grf/p/8719105.html