Javascript两种方法实现数秒自动关闭弹窗

<!--这是window.html文件-->
<script type="text/javascript">
	
   function openWin() {
	<!--
		window.open('http://localhost/Interview/date.php','test_window', 'height=600, width=800, top=111, left=110, toolbar=no, menubar=no');
    -->
   }
</script>
<body οnlοad="openWin()">

</body>

运行后弹出date.php窗口

<script type="text/javascript">
   //自动关闭窗体
   function selfCloseWin() {
		setTimeout("self.close()",5000);
   }

   //数秒倒计时
   var second = 5;
   function change () { 
	  --second;
	  if(second>=0) {
	    document.getElementById("second").innerHTML = second;
		$timer = setTimeout("change()",1000);
	  } else {
	    clearTimeout($timer);
	  }  
   }
   $timer setTimeout("change()",1000);

   //数秒倒计时方法二
   var s = 10;
   function change2 () {
     t=setInterval(function(){s>-1?document.getElementById("second").innerHTML=s--:clearInterval(t);},1000);  
   }
</script>
<body οnlοad="selfCloseWin()">
这个一个弹出窗口,窗口将在
<div id="second" style="color:red;font-size:18px;"></div>秒后自动关闭<br/>
您可以手动关闭<input type="button" name="clink" οnclick="window.close();" value="手动关闭"/><br/>
<?php
  //求时间差
  $time1 = strtotime('5 February 2007');
  $time2 = strtotime('6 March 2007');
  $gap = ceil(($time2-$time1)/(3600*24));
  echo '2007年2月5号于2007年3月6号之间相隔<h2>'.$gap.'</h2>天';
?>
</body>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值