In JavaScript
function(){ alert(“text1”); };
is equivalent to in jquery.
$(window).load(function(){ alert("text1");});
They are all used to run the alert function within a function when all elements of the page, including external reference files, images, etc. are loaded. The Load method can only be executed once, if more than one is written in the JS file, only the last one can be executed. (Beginners often in the page structure of the element directly write behavior function, this is very ugly, you can use selectors and so on, in the JS code to control the elements of the behavior.) )
In jquery
$(document).ready(function(){ alert("text2");});
Equal to (simplified notation)
$(function(){ alert("text2");});
They are all used to execute an internal alert function when a page's standard DOM element is parsed into a DOM tree. This function can be written in the JS file many times, for many people to write a common JS has a great advantage, because all the behavior function will be executed. and $ (document). The Ready () function can be executed after the HMTL structure has been loaded, without the time-consuming tasks such as large file loading or non-existent connections, and the efficiency is high.
Of course, according to the needs of the project to use, such as sometimes the picture or the important information does not come out, will be misleading to user operation, or need to obtain some pictures of high-wide data after the execution of the behavior function, you have to use window.onload.
$ (window). Load (function () {}) and $ (document). The difference between ready (function () {})