addEventListener in Internet Explorer

后端 未结 8 2064
感情败类
感情败类 2020-11-22 14:33

What is the equivalent to the Element Object in Internet Explorer 9?

if (!Element.prototype.addEventListener) {
    Element.prototype.addEventListener = func         


        
8条回答
  •  难免孤独
    2020-11-22 14:56

    I'm using this solution and works in IE8 or greater.

    if (typeof Element.prototype.addEventListener === 'undefined') {
        Element.prototype.addEventListener = function (e, callback) {
          e = 'on' + e;
          return this.attachEvent(e, callback);
        };
      }
    

    And then:

    
    
    
    

    This will work both IE8 and Chrome, Firefox, etc.

提交回复
热议问题