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)
显示时是静态的··想让时间成动态,秒随时在动··
怎么弄?
------解决方案--------------------
- HTML code
<!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>
------解决方案--------------------