The difference between load and onload in JS __js

Source: Internet
Author: User

Copyright NOTICE: This article is the original article of the blogger, without the permission of the blogger may not be reproduced.


In the writing interaction, the load function makes the onload or the load. Tangled under, under Baidu, under Google ...

The opportunity to organize to avoid forgetting.

and JS window.onload (function) equivalent to the jquery $ (window). onload (function)


One: Window.load this should only indicate the event method, but did not execute, such as hover, click to indicate the event, but it did not execute, must use the hover, onclick he will execute

There is usually a loading effect when the page loads the rendering, and you can use it:

Js:

              $ (window). Load (function () {
                $ (". Loadingicon"). AddClass ("Loader-chanage");
                $ (". Loadingicon"). Fadeout (300,function () {
                  $ (". Loadingicon"). Remove ();
                  $ (". Maker"). Show (). Animate ({"Right": "0"},500);
                })
              
            
$ (window). Load (function) page when the picture and other resources are loaded to complete before execution;

However, this method in Window.onload (function) in JS may be executed completely without loading some resources (such as pictures).

Two: Window.onload this means that after loading all the pages of the page to execute, in the page only allow an onload function, because it can be the number of programmable functions only one:

Js:

<! DOCTYPE html>
Run Result:


Three: Say the above there is also a jquery $ (document). Ready (function), after all the DOM structure in the Web page is finished, it is possible that the contents of the DOM element are not loaded, such as the picture and the relative height width of the set, etc. In this case, you can consider the Load method in jquery, and $ (document). Ready (function) can write functions not limited, such as:

<! DOCTYPE html>
Run Result:

Finally, summarize:

The Js:window.onload page executes the function as soon as it is run, and the picture in the page may not have been loaded yet.


jquery: $ (window). When the picture or something else on the load () page finishes loading, execute the function.


The full format of the call load method is: Load (URL, [data], [callback]) parameter URL address, file type (PHP, HTML, etc.), callback function, also support selector load load ("test.html #内容id名")

Copyright NOTICE: This article is the original article, without the owner's permission to reprint.


View the original ....

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.