jquery 和原型冲突
我知道这个问题已经被问过很多次了,我已经在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 noConflict 功能:
确保在此代码之前包含 jQuery 库,这里有一个关于它的文档:
http ://api.jquery.com/jQuery.noConflict/
Use the noConflict capability:
Make sure that you include the jQuery library BEFORE this code, here's a doc on it:
http://api.jquery.com/jQuery.noConflict/
如果您的 userdrive.js 使用全局变量“$”而不使用闭包,它将失败,因为prototype.js 删除了“$”和“jQuery”之间的链接
这是一个闭包:
尝试将您的userdrive 进入闭包并使用 noConflict 方法来防止其他错误。
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:
Try put your userdrive into a closure and uses the noConflict method to prevent other errors.