JQuery $ (document). ready () and JavaScript onload events
JQuery $ (document ). ready () and window. onload according to the ready () method API description http://api.jquery.com/ready/ this method receives a function type parameter ready (handler), the role of the method is: Specify a function to execute when the DOM is fully loaded. that is, when the DOM is loaded, execute the specified method. because only after the document status is ready, page operations are safe. $ (document ). ready () is executed only once when the DOM is ready. in comparison, the load event will wait until the page rendering is complete, that is, when all resources (slice) are fully loaded. $ (window ). load (function (){...}) It will wait for the entire page, not just DOM, but also images and iframes to be ready before execution. ready () is executed after the DOM is ready, that is, when the DOM tree is established. therefore, ready () is a better time. if you call the ready () method after DOM Initialization is complete, the new handler passed in will be executed immediately. note: The ready () method is called multiple times. The passed handler method will be executed in series (appended ). in JavaScript, window. onload is a method for assigning values, that is, the latter will overwrite the previous one. example: <! DOCTYPE html> <meta charset = "UTF-8">