The difference between the read function in jQuery and the onload function in JavaScript, jqueryonload
In JavaScript, the onload function is the most frequently used, and almost all children's shoes involved in JavaScript need to access it. This function is used to execute the statements in the code block after the webpage is fully loaded. It is usually used to load JavaScript in the header according to the execution sequence of the Document Stream.
Copy codeThe Code is as follows:
Window. onload = function (){
// Execute the code block after the webpage is loaded
};
In jQuery, there is also a corresponding function, that is, the code block is executed after the webpage is loaded.
Copy codeThe Code is as follows:
$ (Document). ready (function (){
// Execute the code block after the webpage is loaded
});
The above two seemingly identical functions are actually quite different.
Onload is executed only after the DOM tree is created and all external resources are loaded and the entire page is displayed in the browser window. These resources include not only image resources, but also flash videos embedded on the page. If there are too many images or flash files, the loading takes a long time, this means that the code block execution will be delayed for more time.
In jQuery, the ready () method only needs to wait until the document structure is completely parsed and the browser has converted HTML into a DOM tree, and then runs the code block. Note that only DOM, images in webpages, flash and other external resources are unrelated.
It can be seen that the ready () method in jQuery will shorten the wait time.
Of course, there is another way to put the script behind the <body> label. In this way, the webpage will be executed in the order of document flow, which will also reach onload in JavaScript or ready () in jQuery () in this way, the webpage content is displayed faster.
The problem after the onload function is used in the body of javascript
I guess you probably used the document. write () function. This will overwrite other things.
Differences between jquery and javascript
Jquery is an extension and encapsulation of javascript, which makes javascript easier to use. What people say is jquery is to use less code to perform more functions beautifully.