<body>
<button>开始</button>
<button>停止</button>
<div></div>
<script>
var btn = document.getElementsByTagName("button");
var div = document.getElementsByTagName("div")[0];
var time = 8;
var id = null;
btn[0].addEventListener("click", function () {
id = setInterval(function () {
div.innerHTML = time;
if (time == 0) {
clearInterval(id)
} else {
time--;
}
}, 1000)
}, false)
btn[1].addEventListener("click", function () {
clearInterval(id)
alert("倒计时over")
}, false)
</script>
</body>