悠悠楠杉
网站页面
1、执行一次(延时定时器)
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title> 执行一次</title>
</head>
<body>
<script>
var t1 = window.setTimeout(function() {
console.log('1秒钟之后执行了')
},1000)
//window.clearTimeout(t1) // 去除定时器
</script>
</body>
</html>
2、重复执行(间歇定时器)
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>每隔1秒钟执行一次</title>
</head>
<body>
<script>
var t2 = window.setInterval(function() {
console.log('每隔1秒钟执行一次')
},1000)
//window.clearInterval(t2) // 去除定时器
</script>
</body>
</html>