<html>
<head>
<script   language="javascript" >   
  xx=new Date();  var   s   = (xx.getHours()*3600+xx.getMinutes()*60+xx.getSeconds());     var   tim_d   =   parseInt(s/86400);   
  var   tim_h   =   parseInt((s%86400)/3600);   
  var   tim_m   =   parseInt(((s%86400)%3600)/60);   
  var   tim_s   =   ((s%86400)%3600)%60;   
  function setime()   
  {   
if(tim_s>=60)
{   
tim_s = 0;//60   
if(tim_m>=60)
{   
tim_m=0;//60   
//小时数   
if(tim_h>=24)
{
window.clearTimeout(xx); 
}
tim_h+=1;   
}   
tim_m   +=   1;   
}
tim_s+=1;   
if(tim_s<10)
{
show_s   =   "0"   +   tim_s;   
}
else
{   
show_s   =   tim_s;   
}   

if(tim_m   <   10)
{   
show_m   =   "0"   +   tim_m;   
}
else
{   
show_m   =   tim_m;   
}   
if(tim_h   <   10)
{   
show_h   =   "0"   +   tim_h;   
}
else
{   
show_h   =   tim_h;   
}   
show_d   =   tim_d;
document.getElementById("div1").innerHTML=(show_h+"时"+show_m+"分"+show_s+"秒");   
xx=setTimeout("setime()",1000);   
  }   
  </script> 
  <script   language=javascript defer>   
  var key=1; 
  if(key==1){
  setime(); 
  }  
  </script>
    <body>
 <div id="div1">
 </div>
</body></html>

解决方案 »

  1.   

    没这么麻烦的,简单一点
    <body onload=showTime()>
    <span id=sp> </span>
    </body>
    <script>
    function showTime()
    {
    var o = (new Date()).toLocaleString();
    var t = o.split(" ")[1].split(":")
    var time = t[0]+"时"+t[1]+"分"+t[2]+"秒";
    document.getElementById('sp').innerText = time;
    }
    setInterval("showTime();",1000);
    </script>
      

  2.   

    <HTML>
    <HEAD>
    <TITLE> Test</TITLE>
    <SCRIPT LANGUAGE="JavaScript">  function gettime()  { var t = new Date();  var hours = t.getHours();  var minutes = t.getMinutes();  var seconds = t.getSeconds();  var show_str ="";  show_str +=(hours > 12) ? "下午 ": "上午 ";  show_str += ((hours > 12) ? hours-12 : hours);  show_str += ((minutes <10) ? ":0" : ":") + minutes;  show_str += ((seconds <10) ? ":0" : ":") + seconds;  document.show_time.name1.value = show_str;
    //document.write(show_str);
      t = setTimeout("gettime()",1000);  }
    </SCRIPT>
    </HEAD>
    <BODY onLoad="gettime()">
    <BODY>
    <FORM NAME="show_time" onSubmit="0">
    <INPUT TYPE="text" NAME="name1" SIZE=16 VALUE="">
    </FORM>
    </BODY>
    </HTML>
      

  3.   

    <body onload=showTime()>
    <img src="http://community.csdn.net/logo/images/prj.210.67.gif" id=pic>
    <span id=sp style="position:absolute;left:10;top:20;"> </span>
    </body>
    <script>
    function showTime(){
    var o = (new Date()).toLocaleString();
    var t = o.split(" ")[1].split(":")
    var time = t[0]+"时"+t[1]+"分"+t[2]+"秒";
    document.getElementById('sp').innerHTML = "<font color=blue>"+time+"</font>";
    }setInterval("showTime();",1000);
    </script>