Latest web development tutorials

jQuery callbacks.add () method

jQuery Misc Methods jQuery Misc Methods

Examples

Add a callback function to the list of functions

$ (Function () { var foo = function ( value ) { alert ( "Foo:" + value );}; // Another function will be added to the list var bar = function ( value ) { alert ( "Bar:" + value );}; Var . callbacks = $ Callbacks (); // add the function "foo" to the list callbacks. add ( foo ); // Passing parameters to call all the callback function list callbacks. fire ( "Hello" ); // Output: "foo: hello" // Add the function "bar" to the list callbacks. add ( bar ); // Passing parameters to call all the callback function list callbacks. fire ( "World" ); // Output: // "Foo: world" // "Bar: world" })

try it"

Definition and Usage

callbacks.add () function in the callback list for adding a callback or callback set.

Tip: This method returns a callback object to the callback list it binding.


grammar

callbacks.add( callbacks )

参数 描述
callbacks Function,Array类型 一个函数或者一个函数数组,用来添加到回调列表


jQuery Misc Methods jQuery Misc Methods