清楚定时器的部分没有效果,
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Document</title>
<style>
div {
width: 300px;
margin: 20px 0;
line-height: 30px;
background: yellowgreen;
}
</style>
</head>
<body>
<button id="start">开始</button>
<button id="stop">停止</button>
<div id="box"></div>
<script>
const startBtn = document.getElementById('start');
const stopBtn = document.getElementById('stop');
const box = document.getElementById('box');
var timer;
var show = {
content: "Hello World",
start: function(){
startBtn.addEventListener('click',
()=>{
timer=setInterval(()=>{
box.innerHTML+=this.content;
},1000)
},false);
},
stop: function(){
stopBtn.addEventListener('click',
()=>{
clearInterval(()=>{
timer;
})
},false)
},
}
show.start();
show.stop();
</script>
</body>
</html>
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星