JS Window.onload Event must wait until all content, as well as external images and other files are loaded before the execution.
The jquery entry function is executed after all tags have been loaded.
Then, an explanation of the implementation of the jquery entry function is derived from a cover problem of JS.
JS Entrance function window.onload function has a cover problem, when there are 2 window.onload functions in the document, the latter will overwrite the former, resulting in the function can not be implemented. But jquery has no such problem, it is important because the jquery entry function is just a call to the encapsulated method, except that the arguments are different.
Finally, talk about the jquery entry function (document). Ready ();) implementation.
First, we'll create a function variable called $ in the script tag, and then call it later. Now it doesn't have any effect, because this call is just an empty object, without any arguments. If we want to continue calling after $ (), we need to do something about it. Let's see if there is a ready method in the jquery entry function, we can create an object's property called Ready, then point to an anonymous function, and now we can call it through $ ().
Test with a specific function:
Next, the jquery entry function can pass a function (passed in as a variable) in, that is, $ (). Ready (function () {}) and then received with a parameter (func) variable, then strictly execute the received method, just call (Func ()) on the line.
Let's look at the document parameter before the jquery entry function, which is $ (document). Ready (function () {}), which is exactly the same as the entry function for jquery. It also needs to be received with a variable. Finally, just check the ready function to see if the OnLoad event has (or is not) assigned:
(1) has (is assigned), receives an old function, re-assigns the OnLoad event, and then first calls the new function, then calls the old function, so there is no problem of overwriting, both of them are implemented.
(2) No, directly assigns an onload event.
Finally, let's test, because document does not have the OnLoad event, we can use window to try.
This avoids the problem of function coverage.
The difference between JS entry function and jquery entry function