IE中的事件监听器命令

时间:2012-01-05 17:30:33

标签: javascript internet-explorer event-listener

以下代码按顺序1,2,3,4,5(使用当前版本的FF,Safari,Chrome进行测试)运行功能,但在IE8(我没有IE9)中它们以3,2运行,4,5,1?

是否有按IE提供的顺序运行它们的解决方案?

感谢。

function addEvent( obj, type, fn ){ 
   if (obj.addEventListener){ 
      obj.addEventListener( type, fn, false );
   }
   else if (obj.attachEvent){ 
      obj["e"+type+fn] = fn; 
      obj[type+fn] = function(){ obj["e"+type+fn]( window.event ); } 
      obj.attachEvent( "on"+type, obj[type+fn] ); 
   } 
} 

addEvent(window, 'load', function1);
addEvent(window, 'load', function2);
addEvent(window, 'load', function3);
addEvent(window, 'load', function4);
addEvent(window, 'load', function5);

0 个答案:

没有答案