In the book Management system, useful to Window.onload () {} method, but encountered a problem, is how to do not execute, in the end is why? Worry for a long day. Later, $.ready () {} was replaced by elder sister's guidance. In my shallow understanding that they are the same, then why this line, and that does not? So, online search!
The role of $.ready () {} in jquery is similar to the traditional Window.onload method in JS. But there is a difference with the Windows.onload method.
Difference:
Execution Time:
window.onload () must wait until the contents of the page have been fully loaded before it can be executed, including images.
$.ready () is executed when the DOM structure sinks to completion, without having to wait for the load to complete.
Different number of writes
Window.onload () cannot write multiple at the same time, if there are multiple window.onload () methods, only one
$.ready () can be written multiple at the same time and will be executed.
My window.onload () error occurred because there was an error in the JS other function, which led to his failure to execute. and replaced with $.ready () after the good. Because they have different ways of achieving it.
But not when all use $.ready () is good, for example, if the page has a picture, and this picture has not loaded, use $.ready () to the picture operation, that will certainly be wrong, this time should consider using window.onload (), so each has pros and cons, Use different methods at different times.
The difference between window.onload and $.ready