jQuery deferred.done () method
Examples
When the user clicks the button, the admissibility of lingering objects, triggering a series of callbacks
<Button> Go </ button> <p> Prepare ... </ p> <script> $ (function () {
// When the Deferred object is resolved, three function is called
function fn1 () {$ ( "P" ). Append ( "1" );}
function fn2 () {$ ( "P" ). Append ( "2" );}
function fn3 ( n ) {$ ( "P" ). Append ( n + "3" + n );}
// Create a deferred objects
var . dfd = $ Deferred (); // add a handler to be called when dfd solve the
dfd
// .done () Function to get the number or function of the array . Done ( [ fn1, fn2 ], Fn3, [ fn2, fn1 ] )
// We can also connect to other methods . Done (function ( n ) {$ ( "P" ). Append ( n + "has been completed." );}); // When the button is clicked changed the status to Completed $ ( "Button" ). On ( "Click", function () {
dfd. resolve ( "And" );});}) < / Script>
try it"
Definition and Usage
deferred.done () function when when the Deferred (delay) object is accepted, add a call handler.
Tip: This method takes one or more parameters. deferred.done () returns a Deferred object, you can connect other lingering objects, comprising an additional .done () method. When the Deferred object is resolved, the callback function in the order they are added to the execution, and can be passed as a parameter to the use of the following methods: resolve, resolveWith.
grammar
deferred.done( doneCallbacks [, doneCallbacks ] )
参数 | 描述 |
---|---|
doneCallbacks | Function类型 一个函数或者函数数组,当Deferred(延迟)对象得到解决时被调用 |
doneCallbacks | 可选。Function类型 一个函数或者函数数组,当Deferred(延迟)对象得到解决时被调用 |