首页 > 代码库 > 数码时钟

数码时钟

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>定时器</title>
<style>
img{float: left;}
</style>
<script>
window.onload=function () {
var img=document.getElementsByTagName(‘img‘);
var but1=document.getElementById(‘but1‘);
var but2=document.getElementById(‘but2‘);
var tem=null;
but1.onclick=function () {
function mate() {
var oDate=new Date();
var str=doDou(oDate.getHours())+doDou(oDate.getMinutes())+doDou(oDate.getSeconds());
for(var i=0;i<img.length;i++){
img[i].src=http://www.mamicode.com/‘img/‘+str[i]+‘.jpg‘;
}
}
tem=setInterval(mate,1000);
mate();
}
but2.onclick=function () {
clearInterval(tem);
}
function doDou(n) {
if(n<10){
return ‘0‘+n;
}else{
return ‘‘+n;
}
}
}
</script>
</head>
<body style="font-size: 80px;">
<div style="width: 500px;height: 500px;margin: auto;">
<div style="height: 150px;">
<img src="http://www.mamicode.com/img/0.jpg">
<img src="http://www.mamicode.com/img/0.jpg">
<div style="margin: auto; float: left;">
:
</div>
<img src="http://www.mamicode.com/img/0.jpg">
<img src="http://www.mamicode.com/img/0.jpg">
<div style="margin: auto; float: left;">
:
</div>
<img src="http://www.mamicode.com/img/0.jpg">
<img src="http://www.mamicode.com/img/0.jpg">
</div>
<div>
<input id="but1" type="button" value="http://www.mamicode.com/开始"/>
<input id="but2" type="button" value="http://www.mamicode.com/停止"/>
</div>
</div>

</body>
</html>

数码时钟