<h1>电子时钟</h1>
<p id="p1"></p>
function toDate(n){
if(n<10){
return '0'+n;
}else{
return ''+n;
}
};
window.onload = function(){
function trick(){
var oDate = new Date();
var H = toDate(oDate.getHours());
var M = toDate(oDate.getMinutes());
var S = toDate(oDate.getSeconds());
var t = H +":"+ M +":"+S;
document.getElementById('p1').innerHTML = t;
}
setInterval(trick,1000);
};