shui-performing multiple Window.onload

Source: Internet
Author: User

One, Window.onload () {}

Wait until all the elements in the page that contain the picture are loaded before they can be executed

Two, $ (function () {})

When the DOM structure is drawn, it does not have to wait until the load is complete.

Third, knowledge

Addloadeven: Triggers an event when the page is loaded for the first time

!!! -JavaScript

The first of these methods

Window.onload=function ()
{
FN1 ();
FN2 ();
}
function fn1 ()
{
Alert (' 1 '); Perform 1 first, top-down execution
}
function fn2 ()
{
Alert (' 2 '); Post-execution 2, top-down execution
}

The second method of

OnLoad Event Listener function
function Addloadevent (func)
{
var oldonload=window.onload;
if (typeof window.onload!= "function")
{
Window.onload=func;
}
Else
{
Window.onload=function ()
{
Oldonload ();
Func ();
}
};
}

Function F1 () {alert (' 1 ');}
function F2 () {alert (' 2 ');}
Function F3 () {alert (' 3 ');}
function F4 () {alert (' 4 ');}

Call
Addloadevent (F1);
Addloadevent (F2);
Addloadevent (F3);
Addloadevent (F4);

shui-performing multiple Window.onload

Related Article

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.