Home > Web Front-end > JS Tutorial > Learn jquery from scratch: how to use callback functions_jquery

Learn jquery from scratch: how to use callback functions_jquery

WBOY
Release: 2016-05-16 16:48:00
Original
1088 people have browsed it

In C-like languages, it is usually passed by function pointer/reference.

jquery also provides a similar callback function mechanism. But it's still worth mentioning how to pass the callback function correctly.

1. Callback without parameters

Copy code The code is as follows:

$.get('myhtmlpage.html', myCallBack) ;

Where myCallBack is the function name. Functions are the basis of JavaScript. Can be passed as a reference variable.

2. Callback with parameters

Naturally, according to past experience, we will think that the callback with parameters looks like the following:

Copy code The code is as follows:

$.get('myhtmlpage.html', myCallBack( param1, param2));

But this won’t work properly. myCallBack(param1, param2) will be executed when this statement is called, not after.

The following syntax is correct:

Copy code The code is as follows:

$.get('myhtmlpage.html', function( ){
myCallBack(param1, param2);
});

In this way, the callback function is passed as a function pointer and will be executed after the get operation is completed.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template