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

    回调一词经常见,到底是什么意思呢?

    A callback is a function that is passed as an argument to another function and is executed after its parent function has completed.

    还是英文解释的比较贴切。

    再来一个例子:

    <html> 
    <head> 
    <title>回调函数(callback)</title> 
    <script language="javascript" type="text/javascript"> 
        function a(callback){  
            console.info("我是parent函数a!");
            console.info("调用回调函数callback开始");
            callback(); 
            console.info("调用回调函数callback结束");
        } 
        function b(){ 
        //alert("我是回调函数b"); 
        console.info("我是回调函数b");
        }
        function c(){ 
        //alert("我是回调函数c"); 
         console.info("我是回调函数c");
        } 
    
        function test(){ 
            a(b); 
            a(c); 
        } 
    </script> 
    </head> 
     
    <body> 
        <h1>学习js回调函数</h1> 
        <button onClick=test()>click me</button> 
        <p>测试调用回调函数的顺序</p> 
    </body>  
    </html> 

    执行结果:

  • 相关阅读:
    spring学习10-AOP
    spring学习9-代理模式
    spring学习6-bean的自动装配
    PyQT5使用心得
    Python 时间戳和日期相互转换
    requests模块的入门使用
    Celery异步任务
    MySQL和python交互
    MySQL高级
    MySQL中select的使用
  • 原文地址:https://www.cnblogs.com/fanyong/p/2992554.html
Copyright © 2011-2022 走看看