为什么这个代码后面没反应了啊

来源:8-17 编程练习

一止如水

2018-07-19 12:05

<!DOCTYPE html>
<html>
 <head>
  <title>浏览器对象</title> 
  <meta http-equiv="Content-Type" content="text/html; charset=gkb"/>  
 </head>
 <body>
  <!--先编写好网页布局-->
  <p >操作成功</p>
   <script type="text/javascript">
   dcoument.write("miaoshu()"+"秒后后回到主页");
   function miaoshu(){
        var  i=5;
          i=i-1;
       return i;
   }
         setlnterval(miaoshu(),1000);
         if(miaoshu()==0){
           window.history.back();
       }
      
   
 
   //获取显示秒数的元素,通过定时器来更改秒数。

   //通过window的location和history对象来控制网页的跳转。
  
 </script>
</body>
</html>


写回答 关注

2回答

  • 精慕门0213212
    2018-07-20 17:49:52

     setlnterval(miaoshu(),1000);每次调用miaoshu()你的i都是被赋值为5,返回的值就永远是4!把var i=5;放外面来。document写错了。

    <head>

         <script>

                   var i=5;

                  function miaoshu(){

                       var t1=(i+"秒后进入下一个页面");

                       document.getElementById("clock1").innerText=t1;

                           if(i<=0){

                            window.history.back();

                           }

                       i=i-1;

                  }

                 setInterval(miaoshu, 1000);

         </script>

    <head>

    <body>

         <label id="clock1"></label>

    </body>

  • 是青山
    2018-07-20 00:48:17

    dcoument.write("miaoshu()"+"秒后后回到主页");-------document错了,

    setlnterval(miaoshu(),1000);------函数要加""

    您这个思路我试了一下,走不下去。。。。

JavaScript进阶篇

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

467393 学习 · 21877 问题

查看课程

相似问题