From 76135d85bb7f7a2d8bf9449f97d9d8dd3988e769 Mon Sep 17 00:00:00 2001
From: Leon Xu <6479451-leonxu260@users.noreply.gitlab.com>
Date: Fri, 1 Oct 2021 21:21:34 -0700
Subject: [PATCH] doc: add setTimeout function example
---
source/_posts/Timing.md | 22 +++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)
diff --git a/source/_posts/Timing.md b/source/_posts/Timing.md
index e034163..3f6c186 100644
--- a/source/_posts/Timing.md
+++ b/source/_posts/Timing.md
@@ -45,4 +45,24 @@ let timerId = setTimeout(sayHello, 500);
```javascript
clearTimeout(timerId);
```
-您可以将它们想象为侦听事件“已经过去X秒”并在事件触发时调用函数。
\ No newline at end of file
+您可以将它们想象为侦听事件“已经过去X秒”并在事件触发时调用函数。
+
+# setTimeout函数例子
+```html
+
+
+```
+```javascript
+function init() {
+ id("demo-btn").addEventListener("click", delayedMessage);
+}
+
+function delayedMessage() {
+ id("output-text").textContent = "等待它...";
+ setTimeout(sayHello, 3000);
+}
+
+function sayHello() {
+ id("output-text").textContent = "你好!";
+}
+```
\ No newline at end of file