以倒计时方式显示时间制作的代码 js
<head>
<title>标题页</title>
<META HTTP-EQUIV="REFRESH" CONTENT="11; URL=http://www.google.com">
<script language="JavaScript">
//获取当前时间
startday = new Date();
clockStart = startday.getTime();
function initStopwatch()
{
var myTime = new Date();
var timeNow = myTime.getTime();
var timeDiff = timeNow - clockStart; //获取间隔时间
this.diffSecs = timeDiff/1000; //因为时间以毫秒为单位
return(this.diffSecs); //返回间隔秒数
}
function getSecs()
{
var mySecs = initStopwatch();
var mySecs1 = ""+mySecs;
//以倒计时方式显示时间
mySecs1= 10 - eval(mySecs1.substring(0,mySecs1.indexOf("."))) + "秒";
document.form1.timespent.value = mySecs1;
window.setTimeout('getSecs()',1000);
}
</script>
</head>
<body bgcolor="#ffffff" onLoad="window.setTimeout('getSecs()',1)">
<center>
10秒后将加载页面:
<form name=form1><input size=9 name=timespent></form>
</center>
</body>
</html>