In jQuery, we often use callback functions. In JavaScript, callback functions can be passed as parameters and executed after the current function is executed. How to Use the callback function? There are two types of callback functions: 1. Callback functions without parameters; 2. Callback functions with parameters.Using callback functions without parameters in jQuery$. Get ("myhtmlpage.html", myCallBack callback will call myCallBack after jqueryreceives myhtmlpage.html. Here, myCallBack is not a string, but a defined method name. Here, myCallBack is a method without any parameters.
Using callback functions with parameters in jQuery
$.get( "myhtmlpage.html", function() { myCallBack( param1, param2 ); });Here, we pass an anonymous function, and then call our defined parameter callback function within the anonymous function. Why is an anonymous function used for processing instead of directly passing our callback function? For example, $. get ("myhtmlpage.html", myCallBack (param1, param2); here, myCallBack (param1, param2) returns the value processed by the function, not a function.
This article is from the "SG-YYZ" blog, please be sure to keep this source http://sgyyz.blog.51cto.com/5069360/1297946