-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer1.html
More file actions
35 lines (30 loc) · 926 Bytes
/
timer1.html
File metadata and controls
35 lines (30 loc) · 926 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
window.onload=function () {
var oBtnOn= document.getElementById('btnOn');
var oBtnOff = document.getElementById('btnOff');
//申明变量timer,用于存储定时器
var timer=null;
oBtnOn.onclick=function () {
timer=setInterval(function(){
alert('a');
},5000);
};
oBtnOff.onclick = function () {
//关闭定时器
clearInterval(timer);
alert('定时器已关闭');
};
};
</script>
</head>
<body>
<input id="btnOn" type="button" value="开启" />
<input id="btnOff" type="button" value="关闭" />
</body>
</html>