代码问题求解

来源:8-17 编程练习

颜小夭

2015-03-10 20:02

<!DOCTYPE html>
<html>
 <head>
  <title>浏览器对象</title>  
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>   

  <script type="text/javascript">  
 
   //获取显示秒数的元素,通过定时器来更改秒数。

   //通过window的location和history对象来控制网页的跳转。
   
 var num=5;
 function start()
 {document.getElementById("txt").value=num;
 if(num==0)
 {
    // window.open("http://www.baidu.com/", "_search");
   //  window.open("http://www.baidu.com/", "_self");
 
   window.location.href = "http://www.imooc.com/";
 
     ss();
 }
 if(num>0)
 {num--;
 setTimeout("start()",1000);
 }
}
function ss()
{
    if(num<5)
{num++;
setTimeout("ss()",1000);



}

if(num==5)
{
    window.history.go(-1);
}

 
 }

 </script>
 </head>
 <body onload="start()">
     <p>操作成功</p>
     <input type="text" id="txt">秒后返回到主页
     <span><a href="http://www.imooc.com">返回</a></span>
 </body>

</html>

求大神帮忙看看,我这是只能跳转到慕课,跳不回来了啊

写回答 关注

1回答

  • 康振宁
    2015-03-11 11:29:51

    start()函数中的逻辑是当如果num=0的时候就执行跳转。都已经跳转页面了,怎么可能会往下执行逻辑呢?也就是当num=0的时候start()函数中的第一个判断中,只执行了 window.location.href = "http://www.imooc.com/";这一条语句


JavaScript进阶篇

本课程从如何插入JS代码开始,带您进入网页动态交互世界

467392 学习 · 21877 问题

查看课程

相似问题