定时器
```<!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>Document</title>
</head>
<body>
<script>
function show(){
console.log("1");
}
// 无限次调用
var t=setInterval(show,1000);
// 终止定时器
clearInterval(t);
</script>
</body>
</html>
延时定时器
```<!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>Document</title>
</head>
<body>
<script>
function show(){
console.log("1");
// 如果想用延时定时器实现无限次调用,必须在指定函数内部重新启动一次延时定时器
setTimeout(show,3000);
}
// 延时定时器,间隔多长时间之后,调用一次函数,只调用一次
var t=setTimeout(show,3000);
clearTimeout(t);
</script>
</body>
</html>
<!-- 两种实现无限次调用的区别
1.如果函数的执行时间大于无限定时器的调用时间,会造成函数的积累
2.setTimeout()写在函数的最后,不会在成函数的积累 -->