(1):首先用JS编写实时显示系统时间的函数 clockon() 只有一个参数bgclock,用于指定显示用于转化后的
标记的名称,无返回值,大家进行网站开发时可以将改函数保存在JS文件中,以便重用 代码如下:
<script><BR>function clockon(bgclock)<BR>{<BR> var now = new Date();<BR> var year = now.getYear();<BR> var month = now.getMonth();<BR> var date = now.getDate();<BR> var day = now.getDay();<BR> var hour = now.getHours();<BR> var minu = now.getMinutes();<BR> var sec = now.getSeconds();<BR> var week;<BR> month = month+1;<BR> if(month<10)month="0"+month;<BR> if(date<10)date="0"+date;<BR> if(hour<10)hour="0"+hour;<BR> if(minu<10)minu="0"+minu;<BR> if(sec<10)sec="0"+sec;<BR> var arr_week = new Array("星期日","星期一","星期二","星期三","星期四","星期五","星期六");<BR> week = arr_week[day];<BR> var time = "";<BR> time = year+"年"+month+"月"+date+"日"+week+""+hour+";"+minu+";"+sec;<BR> if(document.all)<BR> {<BR> bgclock.innerHTML="["+time+"]"<BR> }<BR> var timer = setTimeout("clockon(bgclock)",200); <BR>}<BR></script>
(2):在页面的
的onload事件中 调用 以及在要显示的地方放置div标记 代码: