jQuery &原型冲突 [英] jQuery & Prototype Conflict

查看:16
本文介绍了jQuery &原型冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个 html 页面中使用 jQuery AutoComplete 插件,其中我还有一个使用原型的手风琴菜单.

I am using the jQuery AutoComplete plugin in an html page where I also have an accordion menu which uses prototype.

它们都可以完美地单独工作,但是当我尝试在一个页面中实现这两个组件时,我收到了一个我无法理解的错误.

They both work perfectly separately but when I tried to implement both components in a single page I get an error that I have not been able to understand.

未捕获的异常:[异常...组件返回失败代码:0x80004005 (NS_ERROR_FAILURE) [nsIDOMViewCSS.getComputedStyle]"nsresult: "0x80004005 (NS_ERROR_FAILURE)" 位置: "JS 框架 ::file:///C:/文件和设置/管理员/桌面/网站/js/jquery-1.2.6.pack.js ::匿名 :: 第 11 行"数据:无]

uncaught exception: [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIDOMViewCSS.getComputedStyle]" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: file:///C:/Documents and Settings/Administrator/Desktop/website/js/jquery-1.2.6.pack.js :: anonymous :: line 11" data: no]

我发现与 jQuery 冲突的文件是手风琴菜单使用的effects.js".我尝试用较新版本替换此文件,但较新版本似乎破坏了手风琴行为.

I found out the file conflicting with jQuery is 'effects.js' which is used by the accordion menu. I tried replacing this file with a newer version but newer seems to break the accordion behavior.

我的猜测是修改了手风琴中使用的effects.js"文件以获得手风琴演示输出.我还尝试使用 jQuery 需要的覆盖方法来避免与其他库发生冲突,但没有奏效.

My guess is that the 'effects.js' file used in the accordion was modified to obtain the accordion demo output. I also tried using the overriding methods jQuery needs to avoid conflict with other libraries and that did not work.

我从 stickmanlabs.com 获得了手风琴演示.

I obtained the accordion demo from stickmanlabs.com.

并且可以从 jQuery 站点获得 jQuery AutoComplete.

And the jQuery AutoComplete can be obtained from jQuery site.

有其他人遇到过这个问题吗?

Has any one else experienced this issue?

推荐答案

有两种可能的解决方案: 与旧版本的 Scriptaculous 和 jQuery 发生冲突(Scriptaculous 试图错误地扩展原生 Array 原型) - 首先尝试升级您的 Scriptaculous 副本.

There are two possible solutions: There was a conflict with an older version of Scriptaculous and jQuery (Scriptaculous was attempting to extend the native Array prototype incorrectly) - first try upgrading your copy of Scriptaculous.

如果这不起作用,您将需要使用 noConflict()(如上所述).但是,有一个问题.由于您要包含一个插件,因此您需要按特定顺序进行包含,例如:

If that does not work you will need to use noConflict() (as alluded to above). However, there's a catch. Since you're including a plugin you'll need to do the includes in a specific order, for example:

<script src="jquery.js"></script>
<script src="jquery.autocomplete.js"></script>
<script>
  jQuery.noConflict();
  jQuery(document).ready(function($){
    $("#example").autocomplete(options);
  });
</script>
<script src="prototype.js"></script>
<script src="effects.js"></script>
<script src="accordion.js"></script>

希望这有助于澄清情况.

Hope this helps to clarify the situation.

这篇关于jQuery &amp;原型冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆