标签:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>数码时钟</title>
<style>
img{width: 50px; height: 62px;}
</style>
<script>
//不满两位数的,补全零
function toDouble(num){
if(num<10){
return "0"+num;
}
else{
return ""+num;
}
}
window.onload=function(){
var oBtn=document.getElementById(‘btn1‘);
var oSpan=document.getElementsByTagName(‘span‘);
var i=0;
function updatetime()
{
var oDates=new Date();
var arr=toDouble(oDates.getHours())+toDouble(oDates.getMinutes())+toDouble(oDates.getSeconds());//加上‘’把数字转换为字符串
for(i=0;i<oSpan.length;i++){
oSpan[i].innerHTML=arr.charAt(i);
}
}
setInterval(updatetime,1000);
updatetime();
}
</script>
</head>
<body style="background: #000; color: #fff; font-size: 30px;">
<span>0</span>
<span>0</span>
点
<span>0</span>
<span>0</span>
时
<span>0</span>
<span>0</span>
秒
</body>
</html>
标签:
原文地址:http://www.cnblogs.com/liqiong-web/p/5225819.html