JS倒计时10秒 实现功能javascript
实例代码一:css
<html>
<title>倒计时关闭网页</title>
<head>
<script language="javascript">
var cTime=10;//这个变量是倒计时的秒数设置为10就是10秒
function TimeClose()
{
window.setTimeout('TimeClose()',1000);//让程序每秒重复执行当前函数。
if(cTime<=0)//判断秒数若是为0
CloseWindow_Click();//执行关闭网页的操做
this.ShowTime.innerHTML="倒计时"+cTime+"秒后关闭当前窗口";//显示倒计时时间
cTime--;//减小秒数
}
function CloseWindow_Click()
{
window.close();
}
</script>
</head>
<body onLoad="TimeClose();">
<div id="ShowTime">倒计时10秒后关闭当前窗口</div>
<input type="button" name="CloseWindow"
onClick="CloseWindow_Click();" value="当即关闭当前网页">
</body>
</html>html
实例代码二:java
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=gb2312" />
<title>用户管理中心</title>
<link href="Include/Style.Css" rel="stylesheet"
type="text/css" />
<title>请稍等...</title>
<script language="javascript">
<!--
var WaitTime = 10; //等待的时间,单位秒
function WaitDo(){
if(WaitTime > 0){
putOutMsg.innerHTML = "本页面将在"+ WaitTime +"秒钟后自动关闭";
WaitTime --;
setTimeout("WaitDo()",1000);
}
else
{
window.close();
}
}
//-->
</script>
<style type="text/css">
span,font{font-size:16px; font-weight:bold;}
</style>
</head>
<body onLoad="WaitDo();" style="margin:20px;">
<span id="putOutMsg" class="OpenFont"></span>
</body>
</html>函数