zoukankan      html  css  js  c++  java
  • js参考---回调函数

    js参考---回调函数

    一、总结

    一句话总结:

    回调函数是你定义的,但是你没有直接调用,但最终它执行了(在特定条件或时刻),比如 定时器函数 setInterval中的函数参数
    setInterval(function () {
      alert('到点啦!')
    }, 2000)
    什么函数才是回调函数
    ? * 你定义的 * 你没有直接调用 * 但最终它执行了(在特定条件或时刻)

    1、常见的回调函数有哪些?

    a、DOM事件函数
    b、定时器函数
    c、ajax回调函数
    d、生命周期回调函数

    二、回调函数

    博客对应课程的视频位置:

     1 <!DOCTYPE html>
     2 <html lang="en">
     3 <head>
     4   <meta charset="UTF-8">
     5   <title>05_回调函数</title>
     6 </head>
     7 <body>
     8 <button id="btn">测试点击事件</button>
     9 <!--
    10 1. 什么函数才是回调函数?
    11   * 你定义的
    12   * 你没有直接调用
    13   * 但最终它执行了(在特定条件或时刻)
    14 2. 常见的回调函数?
    15   * DOM事件函数
    16   * 定时器函数
    17 
    18   * ajax回调函数(后面学)
    19   * 生命周期回调函数(后面学)
    20 -->
    21 <script type="text/javascript">
    22 
    23   //1. DOM事件函数
    24   var btn = document.getElementById('btn')
    25   btn.onclick = function () {
    26     alert(this.innerHTML)
    27   }
    28 
    29   //2. 定时器函数
    30   setInterval(function () {
    31     alert('到点啦!')
    32   }, 2000)
    33 </script>
    34 
    35 </body>
    36 </html>
     
  • 相关阅读:
    Centos 安装配置iscsi
    Centos 部署Keepalive高可用软件
    Centos 编译安装Haproxy
    Centos 安装 Moosefs文件系统
    docker 存储
    hadoop碰到的 一个问题
    使用curl命令操作elasticsearch
    kafka集群下线broker节点实践方法(broker topic 迁移)
    kafka 安装
    redis3.2.11 安装
  • 原文地址:https://www.cnblogs.com/Renyi-Fan/p/12446587.html
Copyright © 2011-2022 走看看