Jquery +原型冲突

发布于 2024-08-25 22:15:45 字数 1133 浏览 5 评论 0原文

我最近继承了一个以各种方式出现问题的网站。我更喜欢 php,最初 js 工作得很好。我没有对 javascript 或任何包含文件进行任何更改,但在进行了一些内容编辑后,我收到了来自 firebug 的错误。

a.dispatchEvent is not a function
emptyFunction()protot...ects.js (line 2)
emptyFunction()protot...ects.js (line 2)
fireContentLoadedEvent()protot...ects.js (line 2)

[Break on this error] var Prototype={Version:'1.6.0.2',Brows...pe,Enumerable);Element.addMethods();
protot...ects.js (line 2)
this.m_eTarget.setStyle is not a function

[Break on this error] this.m_eTarget.setStyle( { position: 'relative', overflow:'hidden'} );
protot...ects.js (line 43)
uncaught exception: [Exception... "Component returned failure code: 0x80070057 (NS_ERROR_ILLEGAL_VALUE)" nsresult: "0x80070057 (NS_ERROR_ILLEGAL_VALUE)" location: "JS frame :: js/prototype_effects.js :: anonymous :: line 2" data: no]

谷歌搜索我发现一些帖子有时 jquery+prototype 不能很好地发挥作用,重新排列脚本可以解决这个问题,但是由于我没有接触这些部分,所以我不确定我什至需要从哪里开始调试。之前的开发人员合并了一个 head.inc 文件,该文件加载原型、scriptaculous,然后许多页面都在子模板中,为 lightbox 等功能加载 jquery。

该网站临时位于 http://dawn.mikeyhill.com

感谢任何帮助。

I recently inherited a site which is botched in all sorts of ways. I'm more of a php guy and initially the js was working just fine. I made no changes to the javascript or the any of the include files but after making a few content edits I'm getting errors from firebug.

a.dispatchEvent is not a function
emptyFunction()protot...ects.js (line 2)
emptyFunction()protot...ects.js (line 2)
fireContentLoadedEvent()protot...ects.js (line 2)

[Break on this error] var Prototype={Version:'1.6.0.2',Brows...pe,Enumerable);Element.addMethods();
protot...ects.js (line 2)
this.m_eTarget.setStyle is not a function

[Break on this error] this.m_eTarget.setStyle( { position: 'relative', overflow:'hidden'} );
protot...ects.js (line 43)
uncaught exception: [Exception... "Component returned failure code: 0x80070057 (NS_ERROR_ILLEGAL_VALUE)" nsresult: "0x80070057 (NS_ERROR_ILLEGAL_VALUE)" location: "JS frame :: js/prototype_effects.js :: anonymous :: line 2" data: no]

Googling around I found several posts that sometimes jquery+prototype don't play well and rearranging the scripts could fix this issue, however being that I didn't touch these sections I'm not sure where I even need to begin to debug. The previous developer incorporated a head.inc file which loads up prototype, scriptaculous and then many of the pages are in a sub-template loading up jquery for functions like lightbox.

The site is temp housed at http://dawn.mikeyhill.com

Any help is appreciated.

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

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

发布评论

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

评论(1

阳光①夏 2024-09-01 22:15:45

原型库是侵入性的:它向 Javascript 的核心对象添加了各种方法。然后,当通过 for(var k in o) 迭代对象时,迭代将包含这些新方法(因为 Javascript 还不支持不可迭代的属性)。这就是为什么在原型中迭代总是通过诸如each()之类的不受此问题影响的设施来执行。

问题在于其他代码仍然使用旧的“for-var-in”循环。这段代码将会被破坏。在 99% 的 Prototype 无法与其他库一起工作的情况下,问题是由于迭代造成的。

你说你没有触及代码,我相信你,所以这留下了三个选择:

  • 问题之前就存在,但你没有注意到它
  • 有问题的代码仅在特殊情况下执行(由于一些特殊输入)。以前的程序员从未尝试过这种输入。
  • 您所在的那 1% 的问题是由于其他因素造成的:)

The prototype library is intrusive: it adds all sort of methods to core object of Javascript. When objects are then iterated over via for(var k in o) the iteration will include these new methods (because Javascript does not support, yet, non-iterable attributes). That's why in Prototype iteation is always performed via facilities such as each() that are immune to this problem.

The problem is with other code that is still using the good old "for-var-in" loops. This code will break. In 99% of the cases where Prototype does not work with some other library the problem is due to iteration.

You're saying that you didn't touch the code and I believe you so this leaves three options:

  • The problem was there before but you did not notice it
  • The problematic code is executed just in special cases (due to some special input). Previous programmer never tried this input.
  • You are in the 1% where the problem is due to some other factor :)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文