老师帮看下第三个为什么会掉下来
来源:3-13 编程练习
weixin_慕尼黑0465866
2023-02-27 11:16:38
<!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.onclick = () => {
clearInterval(this.timer)
this.timer = setInterval(() => {
box.innerHTML += this.content+" ";
}, 1000)
}
},
stop: function () {
// 在此补充代码
stopBtn.onclick = () => {
clearInterval(this.timer)
}
},
}
// 在此补充代码
show.start();
show.stop();
</script>
</body>
</html>
1回答
imooc_慕慕
2023-02-27
同学你好 ,分析如下;
这里是由于双引号+空格与 不一样导致的,参考修改如下:

祝学习愉快~
相似问题