手记

5s自动跳转setInterval(待分析)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>AutoJump</title>
</head>
<body>
<H4>操作成功</H4>
<p>
    <b id="second">5</b>秒后回到主页<a href="javascript:goBack()">返回</a>
</p>
<script type="text/javascript">
    var sec = document.getElementById("second");
    var i = 5;
    var timer = setInterval(function () {
        i--;
        sec.innerHTML = i;
        if(i==1){
            window.location.href="http://www.imooc.com/";
        }
    },1000);
    function goBack() {
        window.history.go(-1);
    }
</script>

</body>
</html>
<!DOCTYPE html>
<html>
<head>
    <title>浏览器对象</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>
<!--先编写好网页布局-->
<p>操作成功</p>
<p><span id="number">5</span>秒后回到主页<a href="#">返回</a></a></p>

<script type="text/javascript">
    var num = 5;
    function startCount(){
        num --;
        document.getElementById('number').innerHTML = num;
        if(num==1){
            window.location.href = "http://www.imooc.com/";
        }
    }
    setInterval(startCount,1000);
    function goBack(){
        window.history.go(-1);
    }

    //获取显示秒数的元素,通过定时器来更改秒数。

    //通过window的location和history对象来控制网页的跳转。

</script>
</body>
</html>
2人推荐
随时随地看视频
慕课网APP