jquery $ (document). Ready () is similar to the Window.onload method in traditional JavaScript, but it differs from the Window.onload method.
1. Execution time
Window.onload must wait until all elements of the page including the picture have been loaded before they can be executed.
$ (document). Ready () is executed after the DOM structure has been drawn and does not have to wait until the load has finished.
2. Different number of writes
Window.onload cannot write multiple at the same time, if there are multiple window.onload methods, only one
$ (document). Ready () can be written multiple at the same time and can be executed
3. Simplified wording
Window.onload did not simplify the wording
$ (document). Ready (function () {}) can be simply written as $ (function () {});
In my previous development, I used JavaScript in general, and I used the pattern of jquery, which is most of the time, the first line is written:
Copy Code code as follows:
$ (document). Ready (function () {
...
});
This time, not necessarily wait for all the JS and picture loaded, you can execute some methods, but sometimes, must wait for all the
Elements are loaded before you can execute some methods, for example, some pictures or other aspects have not been loaded well, this time, click on some buttons, will cause an unexpected situation, this time,
Need to use:
Copy Code code as follows:
$ (window). Load (function () {
...
});
Summary comparison: