Simple use of jQuery callback Functions
For example, if we want to trigger an event after clicking a button,
First, hide some specified content,
Then, the related information dialog box is displayed.
If you use a common method,
If callback functions are not required,
What will happen?
The result is that the dialog box is displayed before the content is hidden,
Then, hide the specified content.
This is obviously not what we want,
If the callback function is used, this problem can be solved.
Of course, the callback function is far more simple than that ......
The specific code is as follows:
[Html]
<% @ Page language = "java" import = "java. util. *" pageEncoding = "UTF-8" %>
<! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN">
<Html>
<Head>
<Title> My JSP 'myjsp. js' starting page </title>
<Title> test </title>
<Script type = "text/javascript" src = "js/jQuery/jquery-1.4.4.min.js"> </script>
<Script type = "text/javascript">
$ (Document). ready (function (){
$ ("# Button1"). click (function (){
$ ("P"). hide ("slow ");
Alert ("no callback is used. The dialog box is displayed first and then hidden! ");
})
$ ("# Button2"). click (function (){
$ ("P"). hide ("slow", function (){
Alert ("Use the callback function. Hide it first and then the dialog box is displayed! ");
});
})
})
</Script>
</Head>
<Body>
<P>
I love you, java.
<Br>
I love you, java.
<Br>
I love you, java.
<Br>
I love you, java.
<Br>
I love you, java.
<Br>
I love you, java.
<Br>
I love you, java.
<Br>
I love you, java.
<Br>
I love you, java.
<Br>
I love you, java.
<Br>
I love you, java.
<Br>
I love you, java.
<Br>
I love you, java.
</P>
<Input id = "button1" type = "button" value = "no callback function is used! "/>
<Input id = "button2" type = "button" value = "Use the callback function! "/>
</Body>
</Html>