This article mainly introduces window. onload and $ (document ). the difference between ready () and the example analyzes the differences between the two in the use of page elements. For more information, see the example in this article. onload and $ (document ). ready. Share it with you for your reference. The specific analysis is as follows:
Window. onload is a function in Javascript, meaning: Wait for the webpage to load all content (including images );
And $ (deleetn ). ready () can be executed after all DOM structures in the web page are drawn. It may be because the elements associated with the DOM have not been fully loaded, so it is faster;
For example, a simple example:
Window. onload = function () {alert ('I am No.1') ;}; window. onload = function () {alert ('I am no.2 ');}
According to the preceding meaning, only "I am no. 2" can be output"
Replace:
$ (Document ). ready (function () {alert ('I am No.1') ;}); $ (document ). ready (function () {alert ('I am no. 2 ');});
Result output I am No.1, I am no. 2
I hope this article will help you design javascript programs.