<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title> <script type ="text/javascript"> var time = 10; var id=0; window.onload = function () { //时钟每次都会返回一个ID id = setInterval(daojishi, 1000); setTimeout(daojishi,1000);//当window.onload后,再隔1000ms调用指定的方法 } function daojishi() { time--; document.getElementById("time").innerHTML=time; if(time==0) { clearInterval(id);//清除定时器 } } </script> </head> <body> 倒计时 <span id="time"></span>秒 </body> </html>