The definition of jquery callback function and its usage example _jquery

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.