数字时钟(文字类型)

<!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>

posted @ 2016-02-28 22:24  琼琼Daring  阅读(473)  评论(0编辑  收藏  举报