老师,这里如果加节流锁怎么加?
来源:3-13 编程练习
慕UI4313976
2021-08-18 11:00:14
<!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 show = {
content: "Hello World",
timer: null,
start: function () {
// 在此补充代码
startBtn.addEventListener('click',()=>{
clearInterval(this.timer);
this.timer = setInterval(()=>{
box.innerHTML += this.content + ' ';
},1000);
},false)
},
stop: function () {
// 在此补充代码
stopBtn.addEventListener('click',()=>{
clearInterval(this.timer);
},false)
},
}
// 在此补充代码
show.start();
show.stop();
</script>
</body>
</html>
1回答
同学你好,这个问题已经在http://class.imooc.com/course/qadetail/300521中解答过了,建议同学去这个链接中查看。祝学习愉快!
相似问题