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>

  

posted @ 2014-03-12 10:42  erictanghu  阅读(400)  评论(0编辑  收藏  举报