日期:2014-05-16 浏览次数:20338 次
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <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"> function displayTime(){ var today = new Date();//定义日期对象 var hours = today.getHours(); var minutes = today.getMinutes(); var seconds = today.getSeconds(); minutes = fixTime(minutes); seconds = fixTime(seconds); var the_time = hours + ":" + minutes + ":" + seconds; window.document.the_form.showTime.value = the_time;//将时间设置到文本中 the_timeout = setTimeout("displayTime();",1000);//每一秒执行一次函数 function fixTime(the_time){ if(the_time<10){ the_time = "0"+the_time; } return the_time; } } </script> </head> <body onload="displayTime()"> <form name="the_form"> <font face="Arial, Helvetica, sans-serif">当前时间:<input type="text" name="showTime" size="16" /></font> </form> </body> </html>