File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+
Original file line number Diff line number Diff line change 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 >
You can’t perform that action at this time.
0 commit comments