<html>
<head>
<title>无标题文档</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script>
var dayarray=new Array("星期日","星期一","星期二","星期三","星期四","星期五","星期六")
var montharray=new Array("1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月")function getthedate(){
var mydate=new Date()
var year=mydate.getYear()
if (year < 1000)
year+=1900
var day=mydate.getDay()
var month=mydate.getMonth()
var daym=mydate.getDate()
if (daym<10)
daym="0"+daym
var hours=mydate.getHours()
var minutes=mydate.getMinutes()
var seconds=mydate.getSeconds()if (hours<10) {
  hours="0"+hours
}
if (minutes<=9)
minutes="0"+minutes
if (seconds<=9)
seconds="0"+seconds
var cdate="<small><font color='000000' face='Arial'><b>"+year+"年"+montharray[month]+daym+"日 "+dayarray[day]+" "+hours+":"+minutes+":"+seconds+" </b></font></small>"
if (document.all)
document.all.clock.innerHTML=cdate
else if (document.getElementById)
document.getElementById("clock").innerHTML=cdate
else
document.write(cdate)
}
if (!document.all&&!document.getElementById)
getthedate()
function goforit(){
if (document.all||document.getElementById)
setInterval("getthedate()",1000)
}</script>
<body bgcolor="#99CCFF" leftmargin="0" topmargin="3"><span id="clock"></span>
</head><body onLoad="goforit()"></body>
</html>

解决方案 »

  1.   

    <!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=gb2312" />
    <title>无标题文档</title>
    </head>
    <script type="text/javascript">window.onload = function() { 
    var timeContainer = document.getElementById('timeDiv'); 
    setInterval(function() { 
    timeContainer.innerHTML = getMyTime(); 
    },100); 
    } function getMyTime() { 
    var date = new Date(); 
    var h = date.getHours(); 
    var m = date.getMinutes(); 
    var s = date.getSeconds(); 
    var timeStr = date.getFullYear() + '年' + date.getMonth() + '月' + date.getDate() + '日 '; 
    timeStr += (h<10?"0"+h:h)+ ':'; //=========
    timeStr += (m < 10 ? '0' : '') + m + ':'; 
    timeStr += (s < 10 ? '0' : '') + s; 
    return timeStr; 

    </script>
    <body>
    <div id="timeDiv"></div> 
    </body>
    </html>