today=new Date();
var hours = today.getHours();
var minutes = today.getMinutes();
var seconds = today.getSeconds();
var timeValue = ((hours >12) ? hours -12 :hours); 
timeValue += ((minutes < 10) ? "<BLINK>:</BLINK>0" : "<BLINK>:</BLINK>") + minutes;
timeValue += ((seconds < 10) ? "<BLINK>:</BLINK>0" : "<BLINK>:</BLINK>") + seconds;
timeValue += (hours >= 12) ? "<B>pm</B>" : "<B>am</B>";function initArray(){
this.length=initArray.arguments.length
for(var i=0;i<this.length;i++)
this[i+1]=initArray.arguments[i]}var d=new initArray("星期日","星期一","星期二","星期三","星期四","星期五","星期六");
document.write(today.getYear(),"年",today.getMonth()+1,"月",today.getDate(),"日",d[today.getDay()+1]," ",timeValue)显示时是静态的··想让时间成动态,秒随时在动··
怎么弄?

解决方案 »

  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">
    <body>
    <div id=x></div>
    <script>
    function show()
    {
    today=new Date();
    var hours = today.getHours();
    var minutes = today.getMinutes();
    var seconds = today.getSeconds();
    var timeValue = ((hours >12) ? hours -12 :hours); 
    timeValue += ((minutes < 10) ? "<BLINK>:</BLINK>0" : "<BLINK>:</BLINK>") + minutes;
    timeValue += ((seconds < 10) ? "<BLINK>:</BLINK>0" : "<BLINK>:</BLINK>") + seconds;
    timeValue += (hours >= 12) ? "<B>pm</B>" : "<B>am</B>";
    var d=["星期日","星期一","星期二","星期三","星期四","星期五","星期六"];
    document.getElementById("x").innerHTML=today.getFullYear() + "年" + (today.getMonth()+1) + "月"+today.getDate()+"日"+d[today.getDay()] + " " + timeValue;
    }
    window.onload=function()
    {
     setInterval("show()",1000);
    }
    </script>
    </body>
    </html>
      

  2.   

    window.onload=function()
    这句干嘛用的?
      

  3.   


    页面加载时调用此匿名函数
    即setInterval("show()",1000);
      

  4.   

    <div id=x></div>
    这句删了为什么就会出错·显示不了?
      

  5.   

    document.getElementById("x") 你把div删了当然得不到了...
      

  6.   

    getElementById("x")这个有干嘛用???
    快断电了·最后一个问题了·回答了好结贴去了·
      

  7.   


    直接翻译就行了
    根据id访问Element(id是唯一的)
    也就是根据x这个id的值找到了div这个节点
      

  8.   


    LZ,一楼已经给出你想要的答案了。 随便解析一下,那个是getElenmentByid是对id对象的一个引用。