Jquery page loading method (executed after page loading is complete) _ jquery
Source: Internet
Author: User
How to load a page using jquery (execute after the page is loaded). We recommend that you check the differences between windows. onload and $ (document). ready. 1. $ (function (){
$ ("# A"). click (function (){
// Adding your code here
});
});
2. $ (document). ready (function (){
$ ("# A"). click (function (){
// Adding your code here
});
});
3. window. onload = function (){
$ ("# A"). click (function (){
// Adding your code here
});
}
The html code is ClickAnd the js file of jquery needs to be referenced on the page.
The following describes how to call js when loading a page:
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 ");
});
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service