First is the code list of addLoadEvent function:
function addLoadEvent(func){ var oldonload=window.onload; if(typeof window.onload!='function') { window.onload=func; } else { window.onload=function() { oldonload(); func(); } }}To understand it is:
1. Store the value of the existing window.onload event handler function into the variable oldonload;
2. If no function is bound to this processing function, add the new function to it as usual;
3. If some functions are already bound to this processing function, append the new function to the end of the existing instruction.
This function is very practical, especially when the code becomes more and more complicated. No matter how many functions you plan to execute on the page, you can do it by writing one more statement.
The above JS addLoadEvent function is all the content I share with you. I hope you can give you a reference and I hope you can support Wulin.com more.