1. Timing of execution:
window.onload: You must wait for the page to complete (including images, etc.) before executing the package code
$ (document). Ready (): Just wait for the DOM structure in the Web to load and execute the package code
2. Number of executions:
window.onload: Executes only once, if the second time, then the first execution will be overwritten
$ (document). Ready (): can be executed multiple times, nth time will not be overwritten by the last time
3, abbreviated program:
window.onload: None
$ (document). Ready ():$ (function () {
});
In reality, very few use window.onload, because the large elements of the page can be loaded to execute JS code, in the case of slow speed, the page has been fully expanded but the picture is still loading, the page JS interactive function All in suspended animation state, and can only execute words in the development and team development of many times will bring some difficulties.