The Window.onload event is triggered immediately after the page or image is loaded (that is, all the elements have been downloaded). If there are many pictures, music, or falsh,onload events on the page, it will be slow to trigger. So the DOM ready event appears. This event is triggered after the DOM document structure is ready, that is, before the resource is loaded. The Domcontentloaded event is available on many WebKit browsers as well as IE9, which is triggered after the DOM document is ready to be included in the HTML5 standard. For browsers that support this event, using the Domcontentloaded event directly is the simplest and best choice. ie6,7,8 does not support domcontentloaded events. So all of the hack methods are now designed to allow ie6,7,8 to support DOM ready events. The domcontentloaded event is much faster than the OnLoad event, which triggers Document.addeventlistener after the DOM is ready (' domcontentloaded ', function () {alert (" Dom's ready! ")}, False); jquery can manipulate the DOM after the DOM has been loaded (document). Ready (function () {//do something})//The DOM can be manipulated after the document is loaded The document documentation includes additional information such as loading pictures. Window.onload=function () {//do something}//or frequently used images, assuming this document.getElementById ("Imgid"). Onload=function () {//do Something
the difference between DOM ready and DOM load1, Dom ready is done in the DOM after the completion of the DOM can be directly manipulated, such as a picture as long as the tag is complete, do not wait for the picture to be loaded, you can set the image of the width of the property or style, etc. 2, Dom Load is done directly to the DOM after the entire document is loaded (including other information such as loading pictures), such as a picture to be loaded before the icon can be set to the width of the image or style, etc., when the size of the page image is irregular, control the display size, A good solution is to use DOM ready rather than DOM load, because usually the large picture load will be 1.1 points of loading, this in large size, more bytes, slow speed when the performance is very obvious, with the DOM load, usually first put the page open, loading completed and then the picture is reset to a wide height, How much time the picture loads, how long this page will open, the user will be very uncomfortable!! The ready event can be replicated via the readystate State: 1, some implementations of Domready http://www.cnblogs.com/zhangziqiu/archive/2011/06/27/ DOMREADY.HTML2, HTML DOM event http://www.runoob.com/jsref/dom-obj-event.html
OnLoad & Domready