setTimeout的语法功能:
setTimeout() 方法用于在指定的毫秒数后调用函数或计算表达式
小例子:
<!DOCTYPE html>
<head>
<title>setTimeout</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>
<h1>setTimeout</h1>
<span id="content">测试</span>
<script>
setTimeout(function () {
let content = document.getElementById('content');
content.innerHTML = "<div>一秒后</div>";
},1000);
</script>
</body>
</html>
复制代码span标签里面的内容一秒之后由“测试”变成了“一秒后”。
记时器功能:
<!DOCTYPE html>
<head>
<title>setTimeout</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>