onload () and window.onload and $ (document) in body. the difference between ready ():
1, the first two indicate when the page loaded elements (including pictures and other information) performed after the operation, and both in various browsers are compatible, and $ (document). Ready () represents a method in JQuery and thus only supports JQuery is only applicable in the browser, and the method is executed when the DOM node of the page is loaded, without waiting for the picture on the page to finish loading.
2, the current code in the same time in the B ody onload () and window.onload () to note:
A, when the JS code is in the head and the method in window.onload () is anonymous: The method in window will be skipped .
<script type= "Text/javascript" > Alert (' a ');
Window.onload=function () {
Alert (' B ');
} ;
Alert (' C ');
</script>
<body onload= "alert (' d ');" >
</body>
The result in the code above is:a,c,d
bjs code in headwindow.onload () ie8 ie8js code to window.onload () ie8chrome
<script type= "Text/javascript" > Alert (' a ');
WINDOW.ONLOAD=FN ();
function fn () {
Alert (' B ');
} ;
Alert (' C ');
</script>
<body onload= "alert (' d ');" >
</body>
The results are as follows in IE8 and in the following versions:abd, execution results in other browsers are :
A,b,c,d
C, when the JS code in the body while the Method window.onload () is not anonymous:
<body onload= "alert (' a ');" >
<script type= "Text/javascript" > Alert (' B ');
WINDOW.ONLOAD=FN ();
function fn () {
Alert (' C ');
} ;
Alert (' d ');
</script>
</body>
The above code is executed in IE8 and in the following versions: Theresult of B,c,a in other browsers is : b,c,d
D, when The Window,onload () method in the body in the JS code is an anonymous function:
<body onload= "alert (' a ');" >
<script type= "Text/javascript" > Alert (' B ');
Window.onload=function () {
Alert (' C ');
} ;
Alert (' d ');
</script>
</body>
The execution result of the above code is:b,c,d
The JS code is placed in the body and the result in the head is different . This is related to the loading order of the document.
$ (document) in jquery, the difference between ready (), window.onload () in JavaScript, and onload () in body