页面跳转后再点后退按钮,为何firefox上计数值从0开始,其他浏览器上从5开始

来源:8-17 编程练习

ajila

2017-01-07 19:50

<!DOCTYPE html>
<html>
 <head>
  <title>浏览器对象</title>  
  <meta http-equiv="Content-Type" content="text/html; charset=gkb"/>   
 </head>
 <body>
  <!--先编写好网页布局-->
  <h3>操作成功</h3>
  <p>
      <span id="countdown">5</span> 秒后回到主页
      <a href="#tag1" onclick="goBack()">返回</a> 
      <a name="tag1"></a>
  </p>
  
 
  <script type="text/javascript">  

   //获取显示秒数的元素,通过定时器来更改秒数。
    var num = 5;
    function countdownTimer(){
        num--;
        document.getElementById("countdown").innerHTML = num;        
        if(0==num)
        {
            num = 5;
            location = "http://www.imooc.com";            
        }
    }
    var int = setInterval(countdownTimer,1000);   
   //通过window的location和history对象来控制网页的跳转。
   function goBack(){
       clearTimeout(int);
       history.back();  
   }
 </script> 
</body>
</html>


写回答 关注

1回答

  • 慕粉2013053516
    2017-01-08 13:48:56

    你的代码我调试了一下,发现在火狐、谷歌、IE上均没有问题(在我的电脑上)。

JavaScript进阶篇

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

467356 学习 · 21877 问题

查看课程

相似问题