12345678910111213141516171819202122232425262728293031323334353637383940 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- </head>
- <body>
- <button id="btn">测试点击事件</button>
- <!--
- 1.什么函数才是回调函数?
- (1)、你定义的
- (2)、你没有调
- (3)、但最终它执行了(在某个时刻或某个条件下)
- 2.常见的回调函数?
- *DOM事件回调函数==>发生事件的DOM元素(与用户交互)
- *定时器回调函数==>window
- *ajax请求回调函数(与后台交互)
- *生命周期回调函数
- -->
- <script>
- document.getElementById('btn').onclick = function(){//DOM事件回调函数
- alert(this.innerHTML);
- };
- //定时器
- //超时定时器
- //循环定时器
- setTimeout(function(){//定时器回调函数
- alert('到点了');
- },2000);
- </script>
- </body>
- </html>
|