老师请问一下为什么一直输出,暂停按钮没有用呢。浏览器有bug吗
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>setInterval()</title>
<style type="text/css">
div{
width:300px;
height:300px;
border:1px solid #333;
}
</style>
</head>
<body>
<input type="button" value="开始" id="btn">
<input type="button" value="暂停" id="stop">
<br><br>
<div id='text'></div>
<script type="text/javascript">
//补充代码
var btn = document.getElementById('btn')
var stop = document.getElementById('stop')
var text = document.getElementById('text')
var timer = null
var txtAdd = function(){
text.innerHTML += "hello "
}
btn.onclick =function() {
timer = setInterval(txtAdd,1000)
}
stop.onclick = function(){
console.log("hh")
clearInterval(timer)
}
</script>
</body>
</html>
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星