用Javascript编写的倒计时,倒计时完毕后自动关闭页面.
其中TimeCountDown的值是倒计时的时长,单位为秒.默认为10秒.
- <script type="text/javascript">
- document.write("<div id="time_left">Loading</div>");
- document.body.onload=CountDown;
- var TimeCountDown=10;
- function CountDown() {
- window.setTimeout("CountDown()",1000);
- if(TimeCountDown<=0) {
- self.opener=null;
- self.open("","_self");
- self.close();
- }
- document.getElementById("time_left").innerHTML=TimeCountDown+"秒后自动关闭";
- TimeCountDown--;
- }
- </script>
复制代码 |