<button>点击停止定时器</button>
<script>
var btn = document.querySelector('button');
function callback() {
console.log('爆炸了');
}
var timer = setTimeout(callback, 5000);
btn.addEventListener('click', function() {
// 停止定时器
clearTimeout(timer);
})
</script>