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)显示时是静态的··想让时间成动态,秒随时在动··
怎么弄?
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 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>
这句干嘛用的?
页面加载时调用此匿名函数
即setInterval("show()",1000);
这句删了为什么就会出错·显示不了?
快断电了·最后一个问题了·回答了好结贴去了·
直接翻译就行了
根据id访问Element(id是唯一的)
也就是根据x这个id的值找到了div这个节点
LZ,一楼已经给出你想要的答案了。 随便解析一下,那个是getElenmentByid是对id对象的一个引用。