This article mainly introduces document. ready and window. for the difference between onload, if you need it, you can refer to Javascript to execute some operation on it only after the DOM element has been defined. This problem is detailed in the "javascript execution sequence" http://www.jb51.net/article/44577.htmbroke.
JQuery uses document. ready to ensure that the code to be executed is executed when the DOM element is loaded. For example, in the document "jQuery basics-how to get started", I used the following jQuery code:
The Code is as follows:
This Code indicates that a warning message is displayed after the Dom Tree is loaded.
Document. ready () and traditional methodsSimilarly, onload () occurs only after the page is loaded. This includes loading of DOM elements and other page elements (example,
Therefore, the execution speed of the document. ready () method is faster than that of the onload () method.
Note the following two points (from the jQuery document ):
1. Make sure thatThe onload event of the element does not register a function. Otherwise, the $ (document). ready () event may not be triggered. (
I tried to use the following example to demonstrate this situation, but it was not successful, so I think this is only possible .)
The Code is as follows:
My second jQuery
Simple jQuery Example 2
I wowould like to say:
2. You can use the $ (document). ready () event infinitely on the same page. The registered functions are executed sequentially.