老师,这里如果加节流锁怎么加?

来源:3-13 编程练习

慕UI4313976

2021-08-18 11:18:03

<!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回答

好帮手慕然然

2021-08-18

同学你好,这段代码实现节流锁的原理与前面课程​老师所讲的原理差不多,具体实现过程如下:

http://img.mukewang.com/climg/611c7fad0925326610850652.jpg

祝学习愉快!

0

0 学习 · 17877 问题

查看课程