该知道的都知道的,不知道的代码里都有
实现代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>设置计时器</title>
<style>
#box {
margin-top: 100px;
margin-left: 40%;
}
</style>
</head>
<body>
<!-- 显示 开始计时 暂停计时 清空计时 -->
<div id="box">
<h1>0</h1>
<button id="begin">开始</button>
<button id="stop">暂停</button>
<button id="reset">重置</button>
</div>
<script>
// 点击begin开始计时 点击stop暂停计时 点击reset进行重置;进行这三个操作时,h1的内容都要对应变化
// 获取事件源
var box = document.getElementById('box');
var h1 = box.children[0];
var begin = box.children[1];
var stop = box.children[2];
var reset = box.children[3];
var a = 0;
var timer;
begin.addEventListener('click', function