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

为什么跳转页面的方法无论换成location.href或者location.assign()都跳转不过去呢?

<!DOCTYPE html>
<html>
 <head>
  <title>浏览器对象</title>  
  <meta http-equiv="Content-Type" content="text/html; charset=gkb"/>   
 </head>
 <body>
  <!--先编写好网页布局-->
  <h3>操作成功</h3>
  <br>
  <span id="num">5</span>

  <a>秒后回到主页</a>
  <a href="goBack()">返回</a>
 
  <script type="text/javascript">  
 
   //获取显示秒数的元素,通过定时器来更改秒数。
    var max = 5;
    function timer(){
        --max;
        document.getElementById("num").innerHTML = max;
        if(max == 0){
            clearInterval(interval);
            window.location.replace("www.imooc.com");
        }

    }
        var interval = setInterval(timer,1000);
   //通过window的location和history对象来控制网页的跳转。
   function goBack(){
       window.history.back();
   }
 </script>
</body>
</html>

提问者:不过一个她 2018-09-20 14:06

个回答

  • Vanoss
    2018-09-20 14:27:43
    已采纳

    网址请用http://或https://开头