Edit The Code:
See Result »
Try it Yourself - ©
w3big.com
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>本教程(w3big.com)</title> <script src="http://cdn.static.w3big.com/libs/jquery/1.10.2/jquery.min.js"></script> </head> <body> <script> $(function () { // 将被添加到列表的一个简单的函数 var foo = function( value ) { alert( "foo:" + value ); }; var callbacks = $.Callbacks(); // 添加函数 "foo" 到列表 callbacks.add( foo ); // 传入参数调用所有回调列表 callbacks.fire( "hello" ); // 输出: "foo: hello" callbacks.fire( "world" ); // 输出: "foo: world" // 添加另一个函数到列表 var bar = function( value ){ alert( "bar:" + value ); }; // 添加这个函数到列表 callbacks.add( bar ); // 传入参数调用所有回调列表 callbacks.fire( "hello again" ); // 输出: // "foo: hello again" // "bar: hello again" }) </script> </body> </html>