间隔型定时器 setInterval(fun,time)
fun为执⾏的函数
time为间隔执⾏的时间,单位为毫秒,每过time时间就执⾏⼀
次fun⾥⾯的代码
延时型定时器 setTimeout(fun,time)
fun为执⾏的函数
time为延时执⾏的时间,单位为毫秒,经过time时间后执⾏
fun代码,只执⾏⼀次
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<script type="text/javascript">
//间隔型定时器
// setInterval(function(){
// console.log('每3秒输出一次')
// },3000)
//延时型定时器
setTimeout(function(){
alert('延时3秒输出并且仅输出一次')
},2000)
</script>
</body>
</html>