addLoadListener与addEventListener
function addLoadListener(fn){
if(typeof window.addEventListener !='undefined')
{
window.addEventListener('load',fn,false);
}
else if(typeof document.addEventListener !='undefined')
{
document.addEventListener('load',fn,false);
}
else if(typeof window.attachEvent !='undefined')
{
window.attachEvent('onload',fn);
}
else
{
var old=window.onload;
if(window.onload !='function')
{
window.onload=fn;
}
else
{
window.onload=function()
{
old();
fn();
}
}
}
}
function addEventListener(target,eventType,functionRef,capture)
{
if(typeof target.addEventListener !="undefined")
{
target.addEventListener(eventType,functionRef,capture);
}
else if(typeof target.attachEvent !="undefined")
{
target.attachEvent("on"+eventType,functionRef);
}
else
{
eventType="on"+eventType;
if(typeof target[eventType] =="function")
{
var old=target[eventType];
target[eventType]=function()
{
old();
return functionRef();
};
}
else
{
target[eventType]=functionRef;
}
}
}
addLoadListener(x);
function x()
{
alert("xx");
}
而删除addEventListener,又能执行得么,,不晓得是什么原因,,与addEventListener有什么关系?
请高手解答