Skip to content

Commit 0e02543

Browse files
朱安邦的pro电脑朱安邦的pro电脑
authored andcommitted
MODI
1 parent 2eabe96 commit 0e02543

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
### 定时器
2+
window上的方法;共四个
3+
- window.setTimeout 单次定时器
4+
- window.setInterval 间隔定时器
5+
- window.clearTimeout 清除单次定时器
6+
- window.clearInterval 清除间隔定时器
7+
8+
因为浏览器上最大的就是window;所以window不写的,直接写 setTimeout即可;
9+
10+
##### setTimeout
11+
12+
setTimeout() 方法用于在指定的毫秒数后调用函数或计算表达式(间隔的单位上毫秒,1s=1000ms)。
13+
14+
var oBtn=document.getElementById("btn1");
15+
oBtn.onclick=function () {
16+
testClick("2222")
17+
};
18+
function testClick(arg) {
19+
setTimeout(function () {
20+
console.log("hello:"+arg)
21+
},2000);
22+
}
23+
24+
注意:setTimeout() 只执行 function 内的代码 一次。如果要多次调用,请使用 setInterval() 或者 在function内 自身再次调用 setTimeout()。
25+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Window</title>
6+
</head>
7+
<body>
8+
<input type="button" value="click me" id="btn1">
9+
10+
<script>
11+
var oBtn=document.getElementById("btn1");
12+
oBtn.onclick=function () {
13+
testClick("2222")
14+
};
15+
function testClick(arg) {
16+
setTimeout(function () {
17+
console.log("hello:"+arg)
18+
},2000);
19+
}
20+
</script>
21+
</body>
22+
</html>

0 commit comments

Comments
 (0)