Brief analysis of the difference between jQuery of function of {} and of function of {} of jQuery

  • 2020-03-30 01:18:02
  • OfStack

Jquery is an excellent Javascr pt framework. Let's now discuss the functions that are executed after two pages are loaded in Jquery.

The $(document). Ready (function () {
  // write your code here...
}); The code that runs when the DOM load is complete

I could just write it as

JQuery (function () {
});

Function ($) {})(jQuery)
(function () {
}) (jQuery);

It actually executes the ()(para) anonymous method, passing the jQuery object.

The equivalent of
The function of aa ($) {}
Aa (jQuery)

Is a common way to initialize jquery objects.

In layman's terms, execute the code you need after the page loads.
However, sometimes this thing will make the page jump, many JQUERY plug-ins are loaded after the completion of the style change, the page will have a jump or flashing feeling

(funtion () {}) (); Execute the function immediately; It is equivalent to declaring a function and calling it directly after the declaration.

If the parameters are:
(funtion (STR) {alert (STR)}) (" output ")); Funtion OutPutFun(STR){alert(STR); }; OutPutFun (" output ");

JQuery (function () {}); The code used to hold a DOM object that already exists when the code is executed. It cannot be used to hold the code for developing plug-ins because the jQuery object is not passed and the methods (functions) cannot be called externally through jQuery. Method.
(function () {}) (jQuery); The DOM doesn't necessarily exist when you execute the code that holds the code for your plug-in, so be careful with code that automatically performs DOM manipulation.


Related articles: