标签:
HTML CODE:
<!DOCTYPE html>
<html>
<head>
<title>JS</title>
<meta charset="utf-8">
<script src="foo.js"></script>
</head>
<body onload="startTime()">
<div id="timetxt"></div>
</body>
</html>
JS CODE:
function startTime(){
var today = new Date();
var h = today.getHours();
var m = today.getMinutes();
var s = today.getSeconds();
m = checkTime(m);
s = checkTime(s);
document.getElementById("timetxt").innerHTML = h+":"+m+":"+s;
t = setTimeout(function(){
startTime();
},500);
}
function checkTime(i){
if(i<10){
i = "0"+i;
}
return i;
}
标签:
原文地址:http://www.cnblogs.com/htmlphp/p/4813363.html