Jquery +原型冲突
我最近继承了一个以各种方式出现问题的网站。我更喜欢 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
原型库是侵入性的:它向 Javascript 的核心对象添加了各种方法。然后,当通过 for(var k in o) 迭代对象时,迭代将包含这些新方法(因为 Javascript 还不支持不可迭代的属性)。这就是为什么在原型中迭代总是通过诸如each()之类的不受此问题影响的设施来执行。
问题在于其他代码仍然使用旧的“for-var-in”循环。这段代码将会被破坏。在 99% 的 Prototype 无法与其他库一起工作的情况下,问题是由于迭代造成的。
你说你没有触及代码,我相信你,所以这留下了三个选择:
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: