window.onload = function(){
var para =document.createElement("p");
var info = "NodeName:";
info += para.nodeName;
info += " NodeType:";
info += para.nodeType;
alert(info);
}
window.onload = function(){
var para = document.getElementById("testid");
var e = document.createElement("p");
var txt = document.createTextNode("hello zmz");
para.appendChild(e);
e.appendChild(txt);
}
Only the second window.onload is executed, but I want both window.onload to be executed. What to do?
We all know that the onload event can only be executed once, so assuming that you want to run two functions executed during onload, and finally only the function of the latter onload event can be executed, then how do we execute the functions of multiple onload events? The form is as follows :
So, let’s add a function addLoadEvent(func), which only accepts parameters, which is the name of the function that is executed when the page is loadedwindow.addEventListener('load',function(e){state1},false);
window.addEventListener('load',function(e){state2},false);
不建议用onload
It is recommended that one page be used
window.onload
If you are afraid of naming conflicts, you can use a closed space
Method 1
Method 2 is to use the method upstairs.