jquery 和原型冲突

发布于 2025-01-06 01:52:25 字数 1177 浏览 1 评论 0原文

我知道这个问题已经被问过很多次了,我已经在 stackoverflow 和 google 上搜索过答案,但没有一个对我有用,所以也许我的错误是在不同的区域引起的,无论如何,这是我

echo "<script type=\"text/javascript\" src=\"http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js\"></script>\n";

echo "<script type=\"text/javascript\" src=\"javascript/watermark.min.js\"></script>\n";
echo "<script type=\"text/javascript\" src=\"javascript/jquery.cycle.js\"></script>\n";
echo "<script type=\"text/javascript\" src=\"http://vjs.zencdn.net/c/video.js\"></script>\n";

echo "<script type=\"text/javascript\" src=\"javascript/prototype.js\"></script>\n";
echo "<script type=\"text/javascript\" src=\"javascript/scriptaculous.js?load=effects,builder.js\"></script>\n";
echo "<script type=\"text/javascript\" src=\"javascript/lightbox.js\"></script>\n";

echo "<script type=\"text/javascript\" src=\"javascript/jquery.userdrive.js\"></script>\n";

每次放置 prototype.js 时 包含的 javascript 、 scriptaculous.js 和 lightbox.js 在 jQuery 库之后,我的 userdrive 不起作用,当我把它放在前面时,它可以工作但不完全。我知道 $ 符号之间存在冲突,但我不知道如何解决此问题。另外,我的用户驱动器包括 ajax 调用和可排序网格的代码。

I know this question has been asked many times, and I've searched stackoverflow and google for answers but none of them worked for me, so maybe my errors are caused in different areas, anyways here is my javascript includes

echo "<script type=\"text/javascript\" src=\"http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js\"></script>\n";

echo "<script type=\"text/javascript\" src=\"javascript/watermark.min.js\"></script>\n";
echo "<script type=\"text/javascript\" src=\"javascript/jquery.cycle.js\"></script>\n";
echo "<script type=\"text/javascript\" src=\"http://vjs.zencdn.net/c/video.js\"></script>\n";

echo "<script type=\"text/javascript\" src=\"javascript/prototype.js\"></script>\n";
echo "<script type=\"text/javascript\" src=\"javascript/scriptaculous.js?load=effects,builder.js\"></script>\n";
echo "<script type=\"text/javascript\" src=\"javascript/lightbox.js\"></script>\n";

echo "<script type=\"text/javascript\" src=\"javascript/jquery.userdrive.js\"></script>\n";

whenever I put prototype.js, scriptaculous.js and lightbox.js after jQuery library, my userdrive doesn't work, and when I put it before, it works but not completely. I know there is a conflict between the $ signs but I don't know how to fix this. Also, my userdrive includes ajax calls and code for sortable grid.

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

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

发布评论

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

评论(2

涫野音 2025-01-13 01:52:25

使用 noConflict 功能:

<script type="text/javascript" src="other_lib.js"></script>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
  $.noConflict();
  jQuery(document).ready(function($) {
    // Code that uses jQuery's $ can follow here.
  });
  // Code that uses other library's $ can follow here.
</script>

确保在此代码之前包含 jQuery 库,这里有一个关于它的文档:

http ://api.jquery.com/jQuery.noConflict/

Use the noConflict capability:

<script type="text/javascript" src="other_lib.js"></script>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
  $.noConflict();
  jQuery(document).ready(function($) {
    // Code that uses jQuery's $ can follow here.
  });
  // Code that uses other library's $ can follow here.
</script>

Make sure that you include the jQuery library BEFORE this code, here's a doc on it:

http://api.jquery.com/jQuery.noConflict/

复古式 2025-01-13 01:52:25

如果您的 userdrive.js 使用全局变量“$”而不使用闭包,它将失败,因为prototype.js 删除了“$”和“jQuery”之间的链接

这是一个闭包:

(function($){
  ...
})(jQuery)

尝试将您的userdrive 进入闭包并使用 noConflict 方法来防止其他错误。

<script type="text/javascript">
  jQuery.noConflict();
</script>

If your userdrive.js are using the global variable "$" without a closure it will fail because the prototype.js remove the link between "$" and "jQuery"

This is a clousure:

(function($){
  ...
})(jQuery)

Try put your userdrive into a closure and uses the noConflict method to prevent other errors.

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