为了账号安全,请及时绑定邮箱和手机立即绑定

为什么一定设置定时器,那个秒数才会变化?


<!DOCTYPE html>

<html>

 <head>

  <title>浏览器对象</title>  

  <meta http-equiv="Content-Type" content="text/html; charset=gkb"/>   

 </head>

 <body>

  <!--先编写好网页布局-->

  <p>操作成功</p>

  <span id="second">5</span><span>秒后回到主页</span><a href="http://www.imooc.com/qadetail/236877">返回</a>

  <script type="text/javascript">  

    var second=document.getElementById("second").innerHTML;

    function method(){

        second--;

        document.getElementById("second").innerHTML=second;

        if(second==0){

            location.assign("http://www.imooc.com/qadetail/236877");

        }

    }

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

     setInterval(method,1000);

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

   

 </script> 

</body>

</html>


正在回答

1 回答

因为那个定时器的意思是,过多少时间执行一次函数,执行一次函数method()那个数字才会发生变化。

0 回复 有任何疑惑可以回复我~
#1

摄影祖师爷 提问者

非常感谢!
2017-09-21 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

为什么一定设置定时器,那个秒数才会变化?

我要回答 关注问题
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号