本帖最后由 skylinefox 于 2010-11-20 07:44:14 编辑

解决方案 »

  1.   

    var myDate=new Date();//时间对象
    h=myDate.getHours();
    m=myDate.getMinutes();
    s=myDate.getSeconds();//获取时分秒方法seconds=checkTime(s);//转换成24小时格式document.getElementById('txt').innerHTML=h+":"+minutes+":"+seconds;//赋值
            setTimeout('showTime()',500);//定时刷新
    ddd
      

  2.   


    <html> <head> <title>显示时间</title> <script type="text/javascript">function showTime() { //把输出年月日的代码写在函数内就不显示时间了 /*var year; var months; var day;*/ var h; var m; var s; var myDate=new Date(); h=myDate.getHours(); m=myDate.getMinutes(); s=myDate.getSeconds(); /*year=myDate.getFullYear(); months=myDate.getMonth(); day=myDate.getDay(); document.write(year+"年"+months+"月"+day+"日");*/ minutes=checkTime(m); seconds=checkTime(s); document.getElementById('txt').innerHTML=h+":"+minutes+":"+seconds; setTimeout('showTime()',500); } function checkTime(i) { if(i<10) { i="0"+i; return i; } else { return i; } } </script> </head> <body onload="showTime()"> <div id="txt"></div> </body> </html>这样写是有错误的 只显示年月日的  时间的代码好像没执行? 搞不明白~
      

  3.   

    上边的代码太乱我再重新发下<html> 
    <head>
     <title>显示时间</title> 
    <script type="text/javascript">
        function showTime()
           { //把输出年月日的代码写在函数内就不显示时间了 
             /*var year;
                var months;
                var day; */
            var h;
            var m;
            var s;
            var myDate=new Date();
            h=myDate.getHours();
            m=myDate.getMinutes();
            s=myDate.getSeconds();
            /*year=myDate.getFullYear();
               months=myDate.getMonth(); 
               day=myDate.getDay();
               document.write(year+"年"+months+"月"+day+"日");*/
            minutes=checkTime(m);
            seconds=checkTime(s); 
            document.getElementById('txt').innerHTML=h+":"+minutes+":"+seconds;
            setTimeout('showTime()',500);
        }
       function checkTime(i)
       { 
        if(i<10) 
        { i="0"+i; return i; } 
       else { return i; }
       } 
    </script> 
    </head>
     <body onload="showTime()">
     <div id="txt"></div> 
    </body>
     </html>
    这样写不会显示数字.