In jquery code, there is a wide range of application of callback function, it is necessary to have a precise understanding of it, and the following is a simple introduction to this method through an example.
The code example is as follows:
With the callback function, a popup box pops up when the div is all hidden.
<! DOCTYPE Html>"Utf-8"><meta name="author"Content="http://www.jb51.net/"/><title> callback function </title><style type="Text/css">div{height:150px; width:150px; Background-Color:green; Margin-top:10px;}</style><script type="Text/javascript"Src="Mytest/jquery/jquery-1.8.3.js"></script><script type="Text/javascript">$ (document). Ready (function () {$ ("Button"). Click (function () {$ ("Div"). Slideup ( -, function () {alert ("Hide Complete")}); }) }) </script>The code above runs very well and is in order. In many practical applications it is often desirable to have the code complete an action and then do another action.
The code should look the same as the code above, but run the results and not what we expected, but instead pop up the cue box and then hide the div element. This is not to say that Slideup () did not begin execution.
<! DOCTYPE html>
Here's a quick summary of what a callback function is. Look at the following code:
function A () {alert ("I am a Function")}a ();
The above is the most commonly used method of calling functions, called directly with the implementation of the function, but the callback function is not the case, it is to pass its own address as a parameter to another function, when a particular event occurs, it will be passed as a parameter callback function address to invoke the callback function. Take the code that uses the callback function above, which is to pass the address of the function as an argument to the Slideup () method, and when the Slideup () action is completed, the function functions are called by the address parameter passed in.
--------------------------------------------------------------------------------------------------------------- -----------------------------------------------
This article was reproduced from: http://www.jb51.net/article/58862.htm
Application instance parsing of jquery callback function