[i=s] 本帖最后由 蓝宇轩 于 2012-8-11 15:11 编辑 [mw_shl_code=xhtml,true]<!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> <style type="text/css"> body{ background:#CCC;} #mydiv{height:35px;} </style> </head> <body> <div id="mydiv"></div> </body> </html> <script type="text/javascript"> function $$(id){ return document.getElementById(id);//用它来寻找到指定id的div; } function datetime(){ var dt=new Date();//定义一个日期对象; var dttime=dt.getFullYear()+"-";//将时期对象的"年"填充到dttime里;用"-"字符串分开; dttime+=dt.getMonth()+1+"-";//将时期对象的"月"填充到dttime里; dttime+=dt.getDate()+"-";//将时期对象的"日"填充到dttime里; dttime+=dt.getHours()+"-";//将时期对象的"小时"填充到dttime里; dttime+=dt.getMinutes()+"-";//将时期对象的"分"填充到dttime里; dttime+=dt.getSeconds();//将时期对象的"秒"填充到dttime里; $$("mydiv").innerHTML=dttime;//将dttime填充到Div(mydiv)的内容里; setTimeout("datetime()",1000);//每隔1000毫秒(1秒)执行一次上面的函数;时间就在逐渐更新了; } window.onload=datetime;//窗体打开就执行; </script>[/mw_shl_code]