日期:2014-05-16 浏览次数:20390 次
window.onload = function(){
alert(1)
}
if(window.onload){
var old = window.onload;
}
window.onload = function(){
if(typeof old === 'function') old();
alert(2)
}
if(window.addEventListener){
window.addEventListener('load',function(){
alert(1)
},false)
window.addEventListener('load',function(){
alert(2)
},false);
}else{
window.attachEvent('onload',function(){
alert(1)
})
window.attachEvent('onload',function(){
alert(2)
});
}
function addEvent(node,type,listener) {
//使用前面的方法检查兼容性以保证平稳退化
if(node.addEventListener){
//W3C方法--FF
node.addEventListener(type,listener,false);
return true;
}else if(node.attachEvent)
{
//MSIE方法--IE
node['e'+type+listener] = listener;
node[type+listener] = function(){
node['e'+type+listener](window.event);
}
node.attachEvent('on'+type,node[type+listener]);
return true;
}
return false;
}