javascript IE8:对象不支持此属性或方法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7531462/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
IE8: Object doesn't support this property or method
提问by Faili
I know that my issue is known, I just can't figure out a way to fix the problem. However the code works in chrome,ff and safari, but not in ie6-8. I tried to debug the code and following popped up: Line: 272 Error: Object doesn't support this property or method
我知道我的问题是已知的,我只是想不出解决问题的方法。然而,代码在 chrome、ff 和 safari 中有效,但在 ie6-8 中无效。我尝试调试代码并弹出以下内容: 行:272 错误:对象不支持此属性或方法
This is line 272 from my js-file
这是我的 js 文件中的第 272 行
$('#page1')[0].addEventListener('webkitAnimationEnd', self.webkitAnimationEnd, true);
Hav you got an idea what is wrong with it? I'm using jquery <script type="text/javascript" src="js/jquery-1.4.3.min.js">;</script>
which is called in my .html file.
你知道它有什么问题吗?我正在使用<script type="text/javascript" src="js/jquery-1.4.3.min.js">;</script>
在我的 .html 文件中调用的jquery 。
I appreciate any help or useful hint. Thank you in advance.
我感谢任何帮助或有用的提示。先感谢您。
采纳答案by Rafay
use attachEvent
for IE here is a SO link MSIE and addEventListener Problem in Javascript?
使用attachEvent
IE浏览器在这里是一个SO链接在Javascript MSIE使用addEventListener问题?
your code may look like
你的代码可能看起来像
if ( $.browser.msie ) {
$('#page1')[0].attachEvent('webkitAnimationEnd', self.webkitAnimationEnd);
}
hope that will help
希望会有所帮助
回答by Mike G
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);
}