


A brief analysis of the difference between jQuery(function(){}) and (function(){})(jQuery)_jquery
May 16, 2016 pm 05:04 PMJquery is an excellent Javascrīpt framework. Let’s now discuss the functions that are executed after two pages are loaded in Jquery.
$(document).ready(function(){
// Write your code here...
}); Code that runs when the DOM is loaded
can be abbreviated as
jQuery(function(){
});
(function($) {})(jQuery) What does it mean?
(function(){
})(jQuery);
It actually executes the ()(para) anonymous method, but just passes the jQuery object.
Equivalent to
function aa($){}
aa(jQuery)
is the idiomatic way to initialize jquery objects.
In layman's terms, it means executing the code you need after the page is loaded.
However, this thing sometimes makes the page jump. Many JQUERY plug-ins only change the style after the page is loaded, and the page will There is a feeling of jumping or flickering. For example, with the ui.tab plug-in, when there are many page elements, they are all displayed and it forms a TAB. It’s very confusing
(funtion(){})(); execute the function immediately; equivalent to declaring a function first and calling it directly after the declaration;
If the parameters are like:
(funtion(str){alert(str)})("output")); equivalent to: funtion OutPutFun(str){alert(str);};OutPutFun("output" );
jQuery(function(){}); is used to store code that operates DOM objects. The DOM object already exists when the code is executed. It cannot be used to store code for developing plug-ins, because the jQuery object is not passed, and its methods (functions) cannot be called externally through jQuery.method.
(function(){})(jQuery); is used to store the code for developing plug-ins. The DOM may not exist when the code is executed, so please use the code that directly automatically performs DOM operations with caution.

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Detailed explanation of jQuery reference methods: Quick start guide

How to use PUT request method in jQuery?

How to remove the height attribute of an element with jQuery?

jQuery Tips: Quickly modify the text of all a tags on the page

Use jQuery to modify the text content of all a tags

Detailed explanation of the role and function of the MySQL.proc table

Understand the role and application scenarios of eq in jQuery

How to tell if a jQuery element has a specific attribute?
