
<!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><title>计时器</title><style>.bigDiv{margin: 50px auto;width: 200px;height: 200px;background-color: lightskyblue;border-radius: 10px;}#showNum{width: 200px;height: 20px;background-color: orange;text-align-all: center;border-radius: 5px;}</style></head><body><divclass="bigDiv"><h2align="center">计时器</h2><divid="showNum"align="center">
0</div><br><br><divclass="butDiv">    <buttontype="button"id="start">开始</button>
 <buttontype="button"id="stop">停止</button>
 <buttontype="button"id="reset">复位</button>
 </div></div><script>let int=null;
document.getElementById("start").addEventListener('click',function(){if(int==null){
int=setInterval(startNum,1000);}});
document.getElementById("stop").addEventListener('click',function(){clearInterval(int);
int=null;});let num=0;
document.getElementById("reset").addEventListener('click',function(){if(int==null){
num=0;
document.getElementById("showNum").innerHTML= num;}});functionstartNum(){
num++;
document.getElementById("showNum").innerHTML= num;}</script></body></html>