<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> <script language="javascript"> var t = null; t = setTimeout(time,1000);//开始执行 function time() { clearTimeout(t);//清除定时器 dt = new Date(); var h=dt.getHours(); var m=dt.getMinutes(); var s=dt.getSeconds(); document.getElementById("timeShow").innerHTML = "现在的时间为:"+h+"时"+m+"分<span style='color:red'>"+s+"秒</span>"; t = setTimeout(time,1000); //设定定时器,循环执行 } </script> </head> <body> <label id="timeShow"></lable> </body> </html>