This article illustrates the definition and usage of the jquery callback function. Share to everyone for your reference. The specific analysis is as follows:
The jquery code has a wide application to the callback function, it is very necessary to have a precise understanding of it, the following is a simple introduction to this method through an example.
The code example is as follows:
Using the callback function, a prompt box pops up when the div is all hidden.
Copy Code code as follows:
<! DOCTYPE html>
<meta charset= "Utf-8" >
<meta name= "Author" content= "http://www.jb51.net/"/>
<title> Cloud-dwelling community </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 (2000,function () {alert ("hidden")});
})
})
</script>
<body>
<div></div>
<button> Click to view Effect </button>
</body>
The code above works very well and in a very orderly order. In many practical applications, it is often desirable to have the code complete an action before doing another action.
The code appears to be performing the same effect as the code above, but the result is not what we expected, but rather the pop-up balloon before the DIV element. This is not to say that Slideup () did not begin execution.
Copy Code code as follows:
<! DOCTYPE html>
<meta charset= "Utf-8" >
<meta name= "Author" content= "http://www.jb51.net/"/>
<title> Cloud-dwelling community </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 (2000);
Alert ("Hidden Complete");
})
})
</script>
<body>
<div></div>
<button> Click to view Effect </button>
</body>
Here's a simple summary of what a callback function is. Look at the following code:
Copy Code code as follows:
function A () {alert ("I am a Function")}
A ();
The above is the most common way to invoke a function, called directly with the implementation of the function, and the callback function is not, it is passing its own address as an argument to another function, when a specific event occurs, the callback function is used as the parameter passed the callback function address. For the code that uses the callback function, it passes the address of the function functions as an argument to the Slideup () method, and when the Slideup () action completes, the function functions are called by the address arguments passed over.
I hope this article will help you with your jquery programming.