【问题标题】:IE8: Object doesn't support this property or methodIE8:对象不支持此属性或方法
【发布时间】:2012-09-29 19:20:44
【问题描述】:

我知道我的问题是已知的,我只是想不出解决问题的方法。 然而,该代码适用于 chrome、ff 和 safari,但不适用于 ie6-8。 我尝试调试代码并弹出以下代码: 行:272 错误:对象不支持此属性或方法

这是我的 js 文件中的第 272 行

$('#page1')[0].addEventListener('webkitAnimationEnd', self.webkitAnimationEnd, true);

你知道它有什么问题吗?我正在使用在我的 .html 文件中调用的 jquery <script type="text/javascript" src="js/jquery-1.4.3.min.js">;</script>

感谢任何帮助或有用的提示。 提前谢谢你。

【问题讨论】:

  • IE 不支持addEventListener

标签: javascript jquery internet-explorer-8 compatibility


【解决方案1】:

See mozilla docs for problem description and solution

var el = $('#page1')[0];
if (el.addEventListener){
  el.addEventListener('webkitAnimationEnd', self.webkitAnimationEnd, true);
} else if (el.attachEvent){
  el.attachEvent('webkitAnimationEnd', self.webkitAnimationEnd);
}

【讨论】:

    【解决方案2】:

    在 IE 中使用 attachEvent 这是一个 SO 链接 MSIE and addEventListener Problem in Javascript?

    你的代码可能看起来像

    if ( $.browser.msie ) {
    $('#page1')[0].attachEvent('webkitAnimationEnd', self.webkitAnimationEnd);
    }
    

    希望对你有所帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多