1.setTimeout()
间隔多长时间之后再运行,只执行一次
实例:
<!DOCTYPE html>
<html lang="en">
<head>
<title>setTimeout使用</title>
</head>
<body>
<script>
setTimeout("alert('Hello word')",1000);
</script>
</body>
</html>
页面会等待1ms 弹出弹出框,只会弹出一次
2.setInterval()
间隔一段时间执行一次,循环执行
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<script>
setInterval("alert('hello world')",1000);
</script>
</head>
<body>
</body>
</html>
效果:每间隔 1ms 执行一次,接下来循环执行,每隔 1ms 执行一次