IE Javascript 错误“对象不支持此属性或方法”在 jQuery 中

发布于 2024-09-28 06:51:06 字数 963 浏览 9 评论 0原文

由于某种原因,我在 jquery.js(版本 1.4.3,非压缩版本)第 3156 行的 Internet Explorer 8 中收到以下 Javascript 错误:对象不支持此属性或方法 。 Firefox 和 Google Chrome 中不会出现错误。

这是发生错误的行:

if ( (match = Expr.leftMatch[ type ].exec( expr )) != null && match[2] ) {

调查 (console.log(Expr.leftMatch[type])) 产生以下有趣的结果: 在 Google Chrome 中,它输出

/(^(?:.|\r|\n)*?):((?:[\w\u00c0-\uFFFF\-]|\\.)+)(?:\((['"]?)((?:\([^\)]+\)|[^\(\)]*)+)\3\))?(?![^\[]*\])(?![^\(]*\))/

但是在 Internet Explorer 中,这是输出:

function() {
  var p = this;
  do p = p.previousSibling;
  while (p && p.nodeType != 1);
  return p;
}

无法调用 exec(未定义)。 jquery.js 中不存在引用的函数。有谁知道为什么会发生这种情况,或者我能做些什么来解决它?

不幸的是,我还无法创建一个简单的脚本来重现该问题,尽管我确实找到了 有人有同样问题的这篇文章,但它没有提供解决方案(上一篇文章建议页面应该在标准模式下运行,但我的已经是了)。

For some reason, I am getting the following Javascript error in Internet Explorer 8 on line 3156 of jquery.js (version 1.4.3, non-compressed version): Object doesn't support this property or method. No error occurs in Firefox and Google Chrome.

This is the line the error occurs on:

if ( (match = Expr.leftMatch[ type ].exec( expr )) != null && match[2] ) {

Investigation (console.log(Expr.leftMatch[type])) produces the following interesting result: In Google Chrome, it outputs

/(^(?:.|\r|\n)*?):((?:[\w\u00c0-\uFFFF\-]|\\.)+)(?:\((['"]?)((?:\([^\)]+\)|[^\(\)]*)+)\3\))?(?![^\[]*\])(?![^\(]*\))/

However in Internet Explorer this is the output:

function() {
  var p = this;
  do p = p.previousSibling;
  while (p && p.nodeType != 1);
  return p;
}

On which exec cannot be called (it is undefined). The quoted function is not present within jquery.js. Does anyone have any clue why this happens, or what I can do to solve it?

I have, unfortunately, not yet been able to create a simple script to reproduce the problem, although I did find this post of someone having the same problem, but it does not offer a solution (the last post suggests the page should be run in Standards Mode, but mine already is).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

很酷又爱笑 2024-10-05 06:51:06

事实证明,经过几个小时的痛苦之后,我自己设法解决了这个问题。如果您在其他地方定义了 Object.prototype.previousObject,Sizzle 选择器引擎似乎会以这种意想不到的方式中断(并且仅在 Internet Explorer 中)。

删除该声明或将 previousObject 重命名为其他内容可以解决该问题。

有趣的是,我什至自己把代码放在那里(Object.prototype.previousObject = [我问题中的函数]),但我不认识该代码。

好吧,又浪费了充满发展潜力的一天。

As it turns out, I managed to figure it out by myself after several painful hours. It appears the Sizzle selector engine breaks in this unexpected way (and only in Internet Explorer), if you have defined Object.prototype.previousObject elsewhere.

Removing that declaration, or renaming previousObject to something else fixes the problem.

The funny thing is, I even put that code there myself (the Object.prototype.previousObject = [the function in my question]), but I did not recognize the code.

Well, that's another day full of development potential wasted.

沩ん囻菔务 2024-10-05 06:51:06

我发现,如果您尝试向 Object.prototype 添加名为“inherited”的方法,即 Object.prototype.inherited =

它会影响 IE6、7 和 IE6,也会发生相同的行为。 8 但似乎在 IE9(测试版)中已修复

I have discovered the same behaviour occurs if you attempt to add a method called "inherited" to the Object.prototype, ie Object.prototype.inherited = <some func>

It affects IE6, 7 & 8 but seems to be fixed in IE9 (beta)

过去的过去 2024-10-05 06:51:06

可能回复得太晚了,但我也遇到了同样的问题,并通过使用纯 java 脚本而不是 jquery 选择元素来解决!

  var div = document.getElementById("myDiv");
  var rect = div.getBoundingClientRect();

这有点起作用!

May be to late to respond but I had the same problem and solved with selecting elements with plain java script rather then jquery!

  var div = document.getElementById("myDiv");
  var rect = div.getBoundingClientRect();

This works some how!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文