Today I have studied the sequence of onload event execution for window objects,
First, add
<Body> <SCRIPT> alert ('body inlined load'); </SCRIPT> </body>
Then add
<SCRIPT type = "text/JavaScript" src = "./J. js"> </SCRIPT>
The content of J. JS is as follows:
$ (Function (){
Alert ('document init ');
$ (Window). BIND ('load', function (){
Alert ('Bind load ');
});
});
Window. onload = function (){
Alert ('onload ');
}
$ (Function (){
Alert ('document init2 ');
$ (Window). BIND ('load', function (){
Alert ('Bind load2 ');
});
});
The final execution sequence should be
Body inlined Load
Document init
Document init2
Onload
Bind Load
Bind load2
It can be seen that the code written directly to the closest to the body is the first to be executed, followed by the code in jquery's ready function, and then loaded through the window. the code in the onload processing function is finally bound to the processing code through the jquery bind function. If you need to wait until all the elements in the page are loaded before execution, you may specify the window. onload = function () {} or through jquery. bind binding, this is the best thing!