jQuery 原型冲突,替代解决方案

发布于 2024-08-30 20:28:46 字数 196 浏览 6 评论 0 原文

我有一个问题,因为我有条件地包含 IE6 的基于原型的 Lightbox 脚本,因为它比 jQuery 插件工作得更好。

当然,这两个库存在冲突,但官方解决方案对我来说并不是真正可行,因为我必须用替代的无冲突语法替换大量 $ 。

对我来说还有其他解决方案吗?请记住,在我的情况下,让 Prototype 与 jQuery 很好地配合比相反更容易?

I have a problem as I'm conditionally including the Prototype-based Lightbox script for IE6 as it works better than the jQuery plugin.

Of course the two libraries conflict but the official solution is not really feasible for me as i would have to replace tons of $ with the alternative no-conflict syntax.

Is there any other solution for me, keeping in mind that in my case it would be easier to have Prototype work nicely with jQuery than the other way around?

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

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

发布评论

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

评论(3

川水往事 2024-09-06 20:28:46

如果您需要在与 jQuery 代码,您唯一的选择是您不想使用的:jQuery.noConflict

如果您可以限制灯箱在 iframe 中工作,则只能在 iframe 中加载 Prototype,而不能在主窗口中加载。但我怀疑这对于你想做的事情来说太过分了。 :-)

问题是 Prototype 没有无冲突选项(而且现在没有主动计划提供此选项),并且它不容易包含在范围界定函数中以包含符号(因为你真正关心的是全局符号,而不是原型扩展,jQuery 可以使用它)。也就是说,如果您获取prototype.js 文件并将其与灯箱插件的文件组合,将整个内容包装在范围函数中,然后寻找全局符号泄漏,您可能可以做到。这将是一个不平凡的练习,特别是如果您对 Prototype 不太熟悉的话。但如果 iframe 的事情太过分了,那么这可能是从轨道上进行的核攻击。 :-)

Not if you need to use Prototype code (your lightbox thing) in the same window as the jQuery code, your only option there is the one you don't want to use: jQuery.noConflict.

If you could limit the lightbox thing to working in an iframe, you could only load Prototype in the iframe and not your main window. But my suspicion is that that would be overkill for what you're trying to do. :-)

The issue is that Prototype doesn't have a no-conflict option (and right now there's no active plan to provide one) and it's not easily wrapped in a scoping function to contain the symbols (since all you really care about is the global symbols, not the prototype extensions, which jQuery is okay with having around). That said, if you took the prototype.js file and combined it with your lightbox plug-in's file, wrapped the whole thing in a scoping function, and then went hunting for global symbol leaks, you could probably do it. It would be a non-trivial exercise, especially if you're not that familiar with Prototype. But if the iframe thing is overkill, this is probably nuking from orbit. :-)

捎一片雪花 2024-09-06 20:28:46

您可以尝试我在开发基于 Prototype 库的应用程序时所做的操作,但我想要一些 jQuery 功能。

jQuery(document).ready(function($)
{
    $("#BoxLabelRange").next('span').mouseenter(function()
    {
        $("#SearchInformation").slideDown();
    })
})

看到我添加到 document.ready 中的参数了吗,美元符号?在该函数调用中,您可以毫无问题地使用 jQuery“$”别名。对我有用。祝你好运!

You could try what I do when working on an application that's based on the Prototype library, but I want some jQuery functionality.

jQuery(document).ready(function($)
{
    $("#BoxLabelRange").next('span').mouseenter(function()
    {
        $("#SearchInformation").slideDown();
    })
})

See the parameter that I added to the document.ready, the dollar-sign? Within that function call you can use the jQuery "$" alias without any problems. Works for me. Good luck!

深海不蓝 2024-09-06 20:28:46

您是否考虑过看一下您所说的效果不太好的 jQuery 插件(我可以找到几个,可能是这个:http://leandrovieira.com/projects/jquery/lightbox/),并尝试使其在 IE6 中更好地工作?如果需要,请检查原型版本中特定于 IE6 的修复。

我认为这是一个比尝试让 Prototype 和 jQuery 完美结合更好的选择。

Have you considered taking a look at the jQuery plugin that you say doesn't work that well (I can find a couple, could be this one: http://leandrovieira.com/projects/jquery/lightbox/), and attempting to make it work better in IE6? If need be, check for IE6-specific fixes in the Prototype version.

I would consider this a better option than trying to get Prototype and jQuery to play nice together.

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