//参考w3c资料自己编写
网页定时器(时钟的编写)
class="java" name="code"><html>
<head>
<title>28</title>
<script type="text/javascript">
function startTime(){
var today= new Date();
var y=today.getFullYear();
var mon=today.getMonth()+1;
var d=today.getDate();
var h=today.getHours();
var m=today.getMinutes();
var s=today.getSeconds();
mon=checkTime(mon);
d=checkTime(d);
m=checkTime(m);
s=checkTime(s);
document.getElementById("007").innerHTML=""+y+"年"+mon+"月"+d+"日"+" "+h+":"+m+":"+s;
t=setTimeout('startTime()',500);
}
function checkTime(i){
if(i<10)
{i="0"+i;}
return i;
}
</script>
</head>
<body onload="startTime()">
<div id="007" style="background:green;"></div>
</body>
</html>
结果图:
- 大小: 5.4 KB