请老师检查,我的stop按钮为什么没有反应
来源:3-13 编程练习
weixin_慕斯卡0218278
2022-05-23 15:46:19
<script type="text/javascript">
var startBtn = document.getElementById('start');
var stopBtn = document.getElementById('stop');
var 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;
}, 100)
}, false)
},
stop: function () {
stopBtn.addEventListener('click', () => {
clearInterval(this.timer);
})
},
}
show.start();
show.stop();
</script>
1回答
樱桃小胖子
2022-05-23
同学你好,老师测试你的代码,stop按钮是可以正常停止打印的,测试结果如下(GIF图,点击下图查看大图哦):

祝学习愉快!
相似问题