js callback函数

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 function</title>

    <script language="javascript" type="text/javascript">

        function fParent(callback) {

            alert("This is parent function");

            alert("Now call the callback function");

            callback();

        }



        function fCallback1() {

            alert("This is callback function 1");



        }



        function fCallback2() {

            alert("This is callback function 2");



        }



        function test() {

            fParent(fCallback1);

            fParent(fCallback2);

        }

    </script>

</head>



<body>

    <button onClick=test()>click me</button>

</body>

</html>

  

你可能感兴趣的:(callback)