问答详情
源自:8-17 编程练习

大神们 为啥 就是不出来倒计时呢


<!DOCTYPE html>
<html>
 <head>
  <title>浏览器对象</title> 
  <meta http-equiv="Content-Type" content="text/html; charset=gkb"/>  
 </head>
 <body>
  <!--先编写好网页布局-->
  <h2>操作成功</h2>
  <span id="m">5</span>
  <p>秒后返回主页</p>
 <a href="javascript:b();">返回</a>
  <script type="text/javascript"> 
 
   //获取显示秒数的元素,通过定时器来更改秒数。
    var sum=document.getElementById("m").innerHTML;
   function back(){
       sum=sum-1;
       document.getElementById("m").innerHTML=sum;
       if(sum==0){
           window.location.assign("www.baidu.com");
       }
       
   }
   setInterval('back()',1000);}

   //通过window的location和history对象来控制网页的跳转。
   function b(){
       window.history.go(-1);
   }
 </script>
</body>
</html>


提问者:慕粉3491582 2018-09-17 18:28

个回答

  • 春白
    2018-10-09 19:04:19

    试试 window.location.href="https://www.imooc.com";这个跳转

  • 慕粉3491582
    2018-09-17 18:33:08

    解决 倒计时了, setInterval多了 一个 括号  ,可是 倒计时 虽然出来了   ,时间到了 却不跳转呢 是为啥