JQuery $ (document). Ready () and Window.onload
Follow the API description for the Ready () method http://api.jquery.com/ready/.
This method takes the parameter of a function type ready (handler), which is used by the method: Specify a function to execute when the DOM is fully loaded.
That is, the specified method is executed when the DOM has finished loading.Because only the state of document is ready, the operation on the page is safe. $ (document). Ready () executes only once when the DOM is prepared. In contrast, the Load event waits until the page render finishes executing, that is, when all the resources (the slices) are fully loaded.
$ (window). Load (function () {...}) Will wait for the entire page, not just the DOM, but also the images and IFRAMEs are ready and then executed.Ready () is executed after the DOM has been prepared, that is, when the DOM tree is established. So normally ready () is a better time. If the DOM initialization is complete before calling the Ready () method, the incoming new handler will
Execute now.
Note: The Ready () method is called multiple times, and the incoming handler method is executed in tandem (append).
in JavaScript, Window.onload is a method of assigning a value, that is, the latter will overwrite the previous one.$ (document) three shorthand for Ready ()
$ (document). Ready (Handler) $ (). Ready (Handler) (this is not recommended) $ (handler)
The Window object and the Document object Windows object represent the open in the browser: http://www.w3school.com.cn/jsref/dom_obj_window.asp The Document object represents the HTML document that is loaded into the browser: The Http://www.w3school.com.cn/jsref/dom_obj_document.asp Event object events, which represent various states:/HTTP The Www.w3school.com.cn/jsref/dom_obj_event.asp event handle allows us to attach some actions and processes when an event occurs, such as what to do when a button click event occurs. The reference link above contains a list of attributes that can be used to define the behavior of the event, corresponding to various events. The onload of interest in this article is one of the events. OnLoad event onload event: The http://www.w3school.com.cn/jsref/event_onload.asp onload event occurs immediately after the load is complete. (Note that the L is lowercase). The tags supporting the event are: <body>, <frame>, <frameset>, <iframe>, , <link>, <script> The JavaScript objects that support this event are: image, layer, window. Note that there is no document here.
onload usage parsingThe most common is window.onload, and will wait until the entire page and various resources are loaded and then perform the subsequent assignment function behavior. Alternatively, you can use onload in the label, such as:
<body onload= "Inlinebodyonloadtimecounter (); >
where Inlinebodyonloadtimecounter () is a custom JavaScript function. Note that the API documentation for jquery ready () has one of these:
The. Ready () method was generally incompatible with the attribute. If load must be used, either does not use. Ready () or use JQuery's. Load () method to attach load event handlers to the Windo W or to more specific items, like images.
Description The Ready () method and <body onload= "" > are incompatible.
Note: The article originates from reprint.
JQuery $ (document). Ready () and Window.onload