Before the interview, I looked up and tidied up the Window.onload and $ (document). Ready (function () {}) difference, there is time to my blog today, because I am still shallow, if there is a wrong place, also please correct me.
Source: http://www.php100.com/html/program/jquery/2013/0905/5954.html
1, the difference in execution time: window.onload must wait until all the elements in the page (including the picture) are loaded into the browser before they can be executed. and $ (document). Ready (function () {}) is executed when the DOM structure is loaded.
2, write the number of different: Window.onload can not write multiple at the same time, if there are multiple window.onload, then only the last one will be executed, it will cover the front. $ (document). Ready (function () {}) is different, it can be written more than one, and each one will execute.
3, Shorthand method: Window.onload No Shorthand method, $ (document). Ready (function () {}) can be abbreviated to $ (function () {}).
Additionally: Because the event is registered within the (document). Ready () method, as long as the DOM is in place, it is possible that the element's associated file is not downloaded, such as the HTML download for the picture, and has been parsed into the DOM tree, but it is likely that the picture has not been loaded yet. So attributes such as the height and width of the case are not necessarily valid at this time.
To solve this problem, you can use another method in jquery about page loading---the load () method. The load () method binds a handler function in the OnLoad event of the element. If the handler is bound to an element, it is triggered when the content of the element is loaded. such as: $ (window). Load (function () {}) =====window.onload = function () {} ...
Window.onload and $ (document). The difference between ready (function () {})