日期:2014-05-16 浏览次数:20522 次
<html>
 <head>
  <title> New Document </title>
  <script type="text/javascript">
    var i=5;
    function aa(){
        i--;
        var p=document.getElementsByTagName("p")[0];
        p.innerHTML=parseInt(i);
        if(i>0){setTimeout("aa()",1000);}
            
    }   
    
window.onload=function(){
    var two=document.getElementById("two");
        var three=document.getElementById("three");
        var p=document.createElement("p");
        three1=two.lastChild;
        two.insertBefore(p,three1);
        p.innerHTML=i;
        
    setTimeout("window.close()",5000);
    setTimeout("aa()",1000);
}
  </script>
 </head>
 <body>
 <div id="two">
    <center id="three">
      <h6>正在关闭.......</h6>
      </center>
 </div>
 </body>
</html>
------解决方案--------------------
呃,第二个关闭窗口的定时器也没必要设置。
<html>
 <head>
  <title> New Document </title>
  <script type="text/javascript">
    var i=5;
    function aa(){
        i--;
        var p=document.getElementsByTagName("p")[0];
        p.innerHTML=parseInt(i);
        if(i>0){setTimeout("aa()",1000);}else{window.close()}
    }   
    
window.onload=function(){
    var two=document.getElementById("two");
    var three=document.getElementById("three");
    var p=document.createElement("p");
    three1=two.lastChild;
    two.insertBefore(p,three1);
    p.innerHTML=i;
    setTimeout("aa()",1000);
}
  </script>
 </head>
 <body>
 <div id="two">
    <center id="three">
      <h6>正在关闭.......</h6>
      </center>
 </div>
 </body>
</html>
------解决方案--------------------
<html>
  <head>
   <title> New Document </title>
   <script type="text/javascript">
window.onload=function(){
    var two=document.getElementById("two");
    var three=document.getElementById("three");
        setTimeout("window.close()",5000);
    var p=document.createElement("p");
    p.setAttribute("id","time_show");      //添加id的属性,方面下面的值的变化
    p.appendChild(document.createTextNode(""));//这个是在初始化该P元素的值,可以不初始化
    var three1=two.lastChild;
    two.insertBefore(p,three1);  
    
    aa();//初始化时,第一次执行,之后会被setTimeout函数一直执行
}
    v