-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimeout-replace-interval.html
64 lines (55 loc) · 1.07 KB
/
timeout-replace-interval.html
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
#box{
width: 200px;
height: 200px;
background: #322123;
}
body,div{
margin: 0;
padding: 0;
color:#fff;
}
</style>
</head>
<script type="text/javascript">
window.onload=function(){
var executeTime=0;
var intervalTime=500;
var intervalId=0;
var num1=document.getElementById("num1");
var num2=document.getElementById("num2");
var box=document.getElementById("box");
intervalId=setInterval(intervalFun,intervalTime);
function intervalFun(){
executeTime++;
num1.innerHTML=executeTime;
if(executeTime==5){
clearInterval(intervalId);
}
}
var executeTime2=0;
function timeoutFun(){
executeTime2++;
num2.innerHTML=executeTime2;
if(executeTime2<5){
setTimeout(arguments.callee,intervalTime);
}
}
setTimeout(timeoutFun,intervalTime);
}
</script>
<body>
<div id="box">
<span>setInterval:</span>
<span id="num1"></span>
<hr/>
<span>setTimeout:</span>
<span id="num2"></span>
</div>
</body>
</html>