<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
p{
font-size:50px;
width:200px;
height: 100px;
line-height: 100px;
border:1px solid red;
text-align: center;
}
</style>
</head>
<body>
<p id="txt"></p>
<button id="stop">stop</button>
<button id="start">start</button>
<button id="reset1">reset</button>
</body>
<script>
var txt=document.getElementById('txt');
var stop=document.getElementById('stop');
var start=document.getElementById('start');
var reset1=document.getElementById('reset1');
// txt.innerHTML="hello";
// txt.innerHTML="9:58:56";
var hour=0,min=0,sec=0;
txt.innerHTML=hour+":"+min+":"+sec;
var time;
var flag=true;
// var time=setInterval(dao,1000);
function dao(){
sec++;
if(sec==59){
sec=0;
min++;
}
if(min==10){
min=0;
hour++;
}
txt.innerHTML=hour+":"+min+":"+sec;
}
stop.onclick=function(){
flag=true;
clearInterval(time);
}
start.onclick=function(){
if(flag){
flag=false;
time=setInterval(dao,1000);
}
}
reset1.onclick=function(){
hour=0;
min=0;
sec=0;
txt.innerHTML=hour+":"+min+":"+sec;
}
</script>
</html>
评论0