请老师检查作业,谢谢
来源:3-13 编程练习
叫我丽红
2021-07-27 09:53:26
<!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 () {
// 在此补充代码
clearInterval(this.time)
this.time = setInterval(() =>{
console.log(this);
box.innerHTML += show.content;
},1000);
},
stop: function () {
// 在此补充代码
clearInterval(this.time)
},
}
// 在此补充代码
startBtn.addEventListener('click',function(){
show.start();
},false)
stopBtn.addEventListener('click',function(){
show.stop();
},false)
</script>
</body>
</html>
1回答
好帮手慕言
2021-07-27
同学你好,效果是对的,不过show对象中有一个timer属性了,可以使用timer接收定时器的返回值,如下:
另外:单词后面可以加一个空格,让效果更美观,如下:

祝学习愉快~
相似问题