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

为什么秒数不会减

<!DOCTYPE html>
<html>
 <head>
  <title>浏览器对象</title>  
  <meta http-equiv="Content-Type" content="text/html; charset=gkb"/>
  
  
 </head>
 <body>
  <!--先编写好网页布局-->
  <h1>操作成功</h1>
  <b id="time">5</b>秒后回到主页
  <script type="text/javascript">  
 
   //获取显示秒数的元素,通过定时器来更改秒数。
   
   var num=5;
    function time1(){
        num=num-1;
        document.getElementById("time").innerHTML=num;
        if (document.getElementById("time").innerHTML=0){
           window.location.href="http://www.imooc.com";
        }
    }
   setInterval("time1()",1000);
   //通过window的location和history对象来控制网页的跳转。
   function fanhui(){
       window.history.back();
   }
  
  </script>
   <form>
    <input type="button" value="返回" onclick="fanhui()"/>
  </form>
</body>
</html>


正在回答

3 回答

1.document.getElementById("time").innerHTML=0改成==0    2. window.location.href="http://www.imooc.com";应该是window.location.assign="http://www.imooc.com"

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

把if判断里面的document.getElementById("time").innerHTML=0改成num==0

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

举报

0/150
提交
取消

为什么秒数不会减

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信