公路工程质量事故调查:帮忙看看这段JAVASCRIPT代码,想动态显示时间

来源:百度文库 编辑:杭州交通信息网 时间:2024/05/09 10:39:22
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script>
function datetime1()
{
AllMyDate=new Date()
MyYear=AllMyDate.getYear()
MyMonth=AllMyDate.getMonth()
MyDate=AllMyDate.getDate()
MyHours=AllMyDate.getHours()
MyMinutes=AllMyDate.getMinutes()
MySeconds=AllMyDate.getSeconds()
document.write("今天是:")
document.write(MyYear+"年 ")
document.write(MyMonth+"月 ")
document.write(MyDate+"日")
document.write("<br>")
document.write(MyHours+"点 ")
document.write(MyMinutes+"分 ")
document.write(MySeconds+"秒")
setTimeout("datetime1()",1000)
}

</script>
</head>
<body onLoad="datetime1()">
</body>
</html>

楼上正解,我来写代码:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;

charset=gb2312">
<title>无标题文档</title>
<script language="javascript">
function datetime1()
{
AllMyDate=new Date()
var MyYear=AllMyDate.getYear()
var MyMonth=AllMyDate.getMonth()+1
var MyDate=AllMyDate.getDate()
var MyHours=AllMyDate.getHours()
var MyMinutes=AllMyDate.getMinutes()
var MySeconds=AllMyDate.getSeconds()
my.innerHTML="今天是:"+MyYear+"年 "+MyMonth+"月 "+ MyDate+"日

<br>"+MyHours+"点 "+MyMinutes+"分 "+MySeconds+"秒"
setTimeout("datetime1()",1000)
}
</script>
</head>
<body onLoad="datetime1()">
<div id="my"></div>
</body>
</html>

用document.write是不行的。你可以用<input type=text name="XX">
然后再写一个函数来动态改变xx里面的值
用层也可以。。
用层就用INNER来插入值

楼上正解!