javascript 无法获取未定义的属性“替换” - 仅在 IE9 中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17930115/
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
Unable to get property 'replace' of undefined - only in IE9
提问by EHerman
I only receive this error in Internet Explorer 9. IE7, IE8 and IE10 run the script fine. It is a banner of fading images, one after the other all stacked and fade in to each other.
我只在 Internet Explorer 9 中收到此错误。IE7、IE8 和 IE10 可以正常运行脚本。这是一面褪色图像的旗帜,一个接一个地堆叠在一起,彼此淡入淡出。
When you attempt to load the page on IE9, it throws an error. The error occurs within prototype.js and I get this error.
当您尝试在 IE9 上加载页面时,它会引发错误。错误发生在prototype.js 中,我收到此错误。
SCRIPT5007: Unable to get property 'replace' of undefined or null reference prototype.js, line 334 character 24
SCRIPT5007:无法获取未定义或空引用的属性“替换”prototype.js,第 334 行字符 24
Why would this happen in IE9 but not any earlier version??
为什么在 IE9 中会发生这种情况,但在任何早期版本中都不会发生??
回答by Arun Pratap Singh
I was getting the same error message, because I was using a .html() operation on an XML tag.
我收到相同的错误消息,因为我在 XML 标记上使用了 .html() 操作。
var myXML = '<someTag att1=""><cell></cell></someTag>' ;
$(myXML).html(); // which was giving the error msg.
// Instead use the below option
$(myXML).children() ;// instead this work with IE
Note: Above example is not what I actually tried, it's just to give a representation of the problem.
注意:上面的例子不是我实际尝试过的,只是为了说明问题。
回答by v2b
You should try using the X-UA-Compatible tag. Many libraries do not work well with IE9 and need to be run in IE8 compatible mode.
您应该尝试使用 X-UA-Compatible 标签。许多库不能很好地与 IE9 配合使用,需要在 IE8 兼容模式下运行。
<meta http-equiv="X-UA-Compatible" content="IE=8" />
回答by EHerman
I've resolved the issue after a few hours of hair pulling and teeth grinding.
经过几个小时的拔头发和磨牙,我已经解决了这个问题。
I did not realize that scriptaculous was reliant upon prototype.
我没有意识到 scriptaculous 依赖于原型。
I was updating prototype while leaving an outdated version of scriptaculous effects linked which was throwing many errors.
我正在更新原型,同时留下链接的过时版本的脚本效果,这会引发许多错误。
After updating to scriptaculous 1.9 and then updating prototype to 1.7, all was well and no errors are thrown.
更新到 scriptaculous 1.9,然后将原型更新到 1.7 后,一切都很好,没有抛出错误。
Thank you all to those who helped, I appreciate all the comments!
感谢所有帮助我的人,我感谢所有评论!
回答by Faisal E.K
Well, most of the time this error occures because of the .html() operation in jquery to parse XML. Remove this and use .text() instead will solve the problem.
嗯,这个错误的发生大多数时候是因为jquery 中的.html() 操作来解析XML。删除它并使用 .text() 代替将解决问题。