Jquery 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.