<!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>
900字范文,内容丰富有趣,生活中的好帮手!