<!doctype html> 
<html> 
<head> 
<meta charset="utf-8"> 
<title>js 实时的时间</title> 
</head> 
<script> 
function starttime(){ 
var today=new date(); 
var h=today.gethours(); 
var m=today.getminutes(); 
var s=today.getseconds();// 在小于10的数字 前加一个‘0’ 
m=checktime(m); 
s=checktime(s); 
document.getelementbyid('txt').innerhtml=h+":"+m+":"+s; 
t=settimeout(function(){starttime()},500); 
} 
function checktime(i){ 
if (i<10){ 
i="0" + i; 
} 
return i; 
} 
</script> 
<body onload="starttime()"> 
<div id="txt"></div> 
</body> 
</html>
   
 
   