From 9d7756b2d526d0997aa67ae035f0b94c8bd3e38f Mon Sep 17 00:00:00 2001 From: Leon Xu <6479451-leonxu260@users.noreply.gitlab.com> Date: Fri, 1 Oct 2021 21:24:06 -0700 Subject: [PATCH] doc: add setInterval example section --- source/_posts/Timing.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/source/_posts/Timing.md b/source/_posts/Timing.md index 3f6c186..5c173f6 100644 --- a/source/_posts/Timing.md +++ b/source/_posts/Timing.md @@ -65,4 +65,20 @@ function delayedMessage() { function sayHello() { id("output-text").textContent = "你好!"; } +``` + +# setInterval函数例子 +```html + + +``` +```javascript +let timerId = null; //存储interval定时器的ID +function repeatedMessage() { + timerId = setInterval(sayHello, 1000); +} + +function sayHello() { + id("output-text").textContent += "你好!"; +} ``` \ No newline at end of file