第1步,在<head>区域中加入代码:
<META HTTP-EQUIV="REFRESH" CONTENT="11; URL=http://www.jb200.com">
第2步,在<body>中加入代码:
<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= mySecs1.substring(0,mySecs1.indexOf(".")) + " secs."; document.form1.timespent.value = mySecs1 window.setTimeout('getSecs()',1000); } </script> <div style="text-align:center"> This page will change in 10 seconds: <form name=form1><input size=9 name=timespent></form> </div>
第3步,把<body>中内容改为:
<body bgcolor="#fef4d9" onLoad="window.setTimeout('getSecs()',1)">
经过以上三步,即实现了一个页面载入倒计时的功能,大家可以亲自测试下,看看效果如何。