The following describes how to call js when loading a page:
Window. onload = function (){
$ ("Table tr: nth-child (even)"). addClass ("even"); // jquery code
};
This code will be executed after all the documents on the entire page are loaded. Unfortunately, this method not only requires that the DOM tree of the page be fully loaded, but also requires that all external images and resources be fully loaded. Unfortunately, if external resources and sample files take a long time to load, this js effect will make the user feel ineffective.
But the jquery method is used:
$ (Document). ready (function (){
// Any js special effects to be executed
$ ("Table tr: nth-child (even)"). addClass ("even ");
});
You only need to load all the DOM structures and execute the js effect before the browser puts all the HTML into the DOM tree. Including before loading external images and resources.
There is also an abbreviated method:
$ (Function (){
// Any js special effects to be executed
$ ("Table tr: nth-child (even)"). addClass ("even ");
});