读书人

途经就不要错过

发布时间: 2012-10-17 10:25:46 作者: rapoo

路过就不要错过
<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");
function aa()
{
for(var i=5;i>=1;1--)
{
p.innerHTML=parseInt(i);
}
}
three1=two.lastChild;
two.insertBefore(p,three1);
setTimeout("aa()",1000);
}
//-->
</script>
</head>
<body>
<div id="two">
<center id="three">
<h6>正在关闭.......</h6>
</center>
</div>
</body>
</html>
我想做一个关闭网页倒计时的,上述是我写的,不知道哪里错了,请大侠们指点迷津!!!!!!!

[解决办法]
1:是i--,不是1--
2:你的代码我测试不了。改了你的,随便整了个

HTML code
<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 code
<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>
[解决办法]
JScript code
<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函数一直执行}    var i=5;    //全局变量,最好都写在最顶层    function aa(){//这个函数也要写在onload之外        if(i>=1)        {            document.getElementById("time_show").innerHTML=parseInt(i);//innerHTML是通过这样的方式操作的            i--;        }           setTimeout("aa()",1000);   //这个只会执行一次,所以要放在自己会调用的函数中,才会一直执行,或者改成setInterval函数执行    } </script>  </head>  <body>  <div id="two"> <center id="three">   <h6>正在关闭.......</h6>   </center>  </div>  </body></html> 

读书人网 >JavaScript

热点推荐