The usage is as follows:
function func(){alert("this is window onload event!");return;}
=func;
Or as follows:
=function(){alert("this is window onload event!");return;}
However, multiple functions cannot be loaded at the same time.
for example:
function t(){
alert("t")
}
function b(){
alert("b")
}
=t ;
=b ;
The previous one will be overwritten later, and the above code will only output b.
At this time, the following methods can be used to solve the problem:
=function() { t(); b(); }
Another solution is as follows:
function addLoadEvent(func) {
var oldonload = ;
if (typeof != 'function') {
= func;
} else {
= function() {
oldonload();
func();
}
}
}
Use as follows:
function t(){
alert("t")
}
function b(){
alert("b")
}
function c(){
alert("c")
}
function addLoadEvent(func) {
var oldonload = ;
if (typeof != 'function') {
= func;
} else {
= function() {
oldonload();
func();
}
}
}
addLoadEvent(t);
addLoadEvent(b);
addLoadEvent(c);
//Equivalent to =function() { t(); b(); c() ;}
I personally think it is faster to use implicit functions directly (such as: =function() { t(); b(); c() ;}). Of course, using addLoadEvent is more professional, so everyone can do it!
function func(){alert("this is window onload event!");return;}
=func;
Or as follows:
=function(){alert("this is window onload event!");return;}
However, multiple functions cannot be loaded at the same time.
for example:
Copy the codeThe code is as follows:
function t(){
alert("t")
}
function b(){
alert("b")
}
=t ;
=b ;
The previous one will be overwritten later, and the above code will only output b.
At this time, the following methods can be used to solve the problem:
=function() { t(); b(); }
Another solution is as follows:
Copy the codeThe code is as follows:
function addLoadEvent(func) {
var oldonload = ;
if (typeof != 'function') {
= func;
} else {
= function() {
oldonload();
func();
}
}
}
Use as follows:
Copy the codeThe code is as follows:
function t(){
alert("t")
}
function b(){
alert("b")
}
function c(){
alert("c")
}
function addLoadEvent(func) {
var oldonload = ;
if (typeof != 'function') {
= func;
} else {
= function() {
oldonload();
func();
}
}
}
addLoadEvent(t);
addLoadEvent(b);
addLoadEvent(c);
//Equivalent to =function() { t(); b(); c() ;}
I personally think it is faster to use implicit functions directly (such as: =function() { t(); b(); c() ;}). Of course, using addLoadEvent is more professional, so everyone can do it!