html 中的 Javascript 顺序

发布于 2024-10-14 13:27:23 字数 798 浏览 6 评论 0原文


我的 javascript 文件有问题,即。有些脚本不起作用,具体取决于我在 html 文件中订购它们的方式。这里是演示,只是为了向您展示我的意思: http://testground.uphero.com/test/

正如您在源代码中看到的那样:

<script type="text/javascript" src="js/prototype.js"></script> 
<script type="text/javascript" src="js/scriptaculous.js?load=effects,builder"></script> 
<script type="text/javascript" src="js/lightbox.js"></script> 
<script src="http://code.jquery.com/jquery-1.4.4.js" type="text/javascript"></script> 
<script type="text/javascript" src="js/grayscale.img.js"></script>

如果我按此顺序放置标签,灰度 img 将起作用,而 Lightbox 将不起作用,但如果我将 jquery 链接移至顶部,灰度将不再起作用,但 Lightbox 将起作用。

所以我想要的是让它们都工作。有什么办法吗。提前致谢! :-)

I'm having a problem with javascript files ie. some scripts don't work depending of way i order them in html file.Here is demo just to show you what i mean:
http://testground.uphero.com/test/

As you can see in source there is:

<script type="text/javascript" src="js/prototype.js"></script> 
<script type="text/javascript" src="js/scriptaculous.js?load=effects,builder"></script> 
<script type="text/javascript" src="js/lightbox.js"></script> 
<script src="http://code.jquery.com/jquery-1.4.4.js" type="text/javascript"></script> 
<script type="text/javascript" src="js/grayscale.img.js"></script>

If i put tags in this order Grayscale img will work and Lightbox won't but if i move jquery link to the top Grayscale will no longer work however Lightbox will work.

So what i want is to make them both work. Is there any way. Thanks in advance! :-)

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

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

发布评论

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

评论(2

他不在意 2024-10-21 13:27:23

正如我在评论中所说:你应该避免使用两个框架,但是:

如果你真的必须使用这两个框架,请使用 firebug (或其他浏览器的类似工具)来查看生成的 javascript 错误 - 也许你必须激活“两个框架都使用“兼容性/无冲突模式”,因此它们不会互相杀死。

有关详细信息,请参阅 jQuery 文档

As I said in my comment: thy to avoid using two frameworks, but:

if you really have to use both, use firebug (or something similar for other browsers) to see the resulting javascript errors - maybe you'll have to activate the "compatibility/noconflict mode" for both frameworks, so they don't kill each other.

Take a look at the jQuery documentation for more information about this.

昔梦 2024-10-21 13:27:23

您的问题可能是由于与 Prototype 和 jQuery 使用的命名空间发生冲突 - 它们都引用 $ 作为其命名空间的快捷方式。尝试同时使用这两个库,您将不可避免地遇到冲突。

这是一篇关于将 jQuery 与其他库一起使用的有用文章,包括如何解决该问题:

http://docs.jquery .com/Using_jQuery_with_Other_Libraries

但是,您需要小心确保您正在使用的插件在正确的范围内引用,以便每个库正常工作。如果可能的话,坚持只使用一个库可能是更明智的选择(有很多可用于 jQuery 的 lightbox 克隆)。

Your problem is likely due to a conflict with the namespaces used by Prototype and jQuery — they both reference $ as a shortcut to their namespaces. Try to use both libraries together and you will inevitably run into conflicts.

Here's a useful article on using jQuery with other libraries, including how you can work around the problem:

http://docs.jquery.com/Using_jQuery_with_Other_Libraries

However, you will need to be careful to make sure that the plugins you are using are referenced within the correct scope for each library to work properly. If at all possible, it's probably wiser to stick to using only one library (there are plenty of lightbox clones available for jQuery).

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