其他分享
首页 > 其他分享> > 开始setInterval 停止clearInterval 函数

开始setInterval 停止clearInterval 函数

作者:互联网

<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<title>setInterval使用方法</title>
<style type="text/css">
.com {
width: 200px;
height: 30px;
background-color: burlywood;
/* color: orange; */
line-height: 30px;
font-family: serif;
text-align: center;
}

.hand {
display: inline-block;
background: #333;
border-radius: 4px;
width: 28px;
height: 28px;
margin: 0 5px;
font-size: 18px;
color: #fff;
vertical-align: middle;
text-align: center;
line-height: 28px;
}
</style>
</head>

<body>
<script type="text/javascript">
window.addEventListener('load', function() {
var stop = document.querySelector('.stop');
var b = document.querySelector('.begin');
// b.addBehavior('click')
var timer = null;
b.addEventListener('click', function() {
timer = setInterval(function() {
console.log('开始计时');
}, 1000)
})
stop.addEventListener('click',function(){
clearInterval(timer);
})
})
</script>
<button class="stop">停止</button>
<button class="begin">开始</button>
</body>

</html>

标签:function,函数,setInterval,clearInterval,height,color,28px,addEventListener,click
来源: https://www.cnblogs.com/witchery/p/16630949.html