01.回调函数.html 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. </head>
  9. <body>
  10. <button id="btn">测试点击事件</button>
  11. <!--
  12. 1.什么函数才是回调函数?
  13. (1)、你定义的
  14. (2)、你没有调
  15. (3)、但最终它执行了(在某个时刻或某个条件下)
  16. 2.常见的回调函数?
  17. *DOM事件回调函数==>发生事件的DOM元素(与用户交互)
  18. *定时器回调函数==>window
  19. *ajax请求回调函数(与后台交互)
  20. *生命周期回调函数
  21. -->
  22. <script>
  23. document.getElementById('btn').onclick = function(){//DOM事件回调函数
  24. alert(this.innerHTML);
  25. };
  26. //定时器
  27. //超时定时器
  28. //循环定时器
  29. setTimeout(function(){//定时器回调函数
  30. alert('到点了');
  31. },2000);
  32. </script>
  33. </body>
  34. </html>