Usage is as follows:
function func () {alert ("This is window onload event!"); return;}
Window.onload=func;
Or as follows:
Window.onload=function () {alert ("This is window onload event!"); return;}
However, window.onload cannot load multiple functions at the same time.
Like what:
Copy Code code as follows:
function T () {
Alert ("T")
}
Function B () {
Alert ("B")
}
Window.onload =t;
Window.onload =b;
The previous overlay will be followed, and the above code will only output B.
The following methods can be used to resolve this:
Window.onload =function () {t (); B ();}
The other solution is as follows:
Copy Code code as follows:
function Addloadevent (func) {
var oldonload = window.onload;
if (typeof window.onload!= ' function ') {
Window.onload = func;
} else {
Window.onload = function () {
Oldonload ();
Func ();
}
}
}
Use the following:
Copy Code code as follows:
function T () {
Alert ("T")
}
Function B () {
Alert ("B")
}
Function C () {
Alert ("C")
}
function Addloadevent (func) {
var oldonload = window.onload;
if (typeof window.onload!= ' function ') {
Window.onload = func;
} else {
Window.onload = function () {
Oldonload ();
Func ();
}
}
}
Addloadevent (t);
Addloadevent (b);
Addloadevent (c);
Equivalent to Window.onload =function () {t (); B (); C ();}
Individuals assume that implicit functions (such as: Window.onload =function () {t (); B (); C ();}) are used directly. Faster, of course, use addloadevent more professional, each take the good!