在同一页面上使用不同版本的jQuery [英] Using different versions of jQuery on the same page

查看:94
本文介绍了在同一页面上使用不同版本的jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的服务用户在我提供的页面中包含一个JS.我正在托管其中包括的脚本.我的脚本对其内容进行了一些操作.我讨厌编写自己的DOM操纵器/选择器,并且如果可以使用jQuery,则浪费大量的工作来完成可以用1行代码完成的工作.

Users of my service includes a JS in their pages that I provide. I am hosting the script they are including. My script does some manipulation on their content. I am sick of writing my own DOM manipulators/selectors and wasting hours for jobs that can be done with 1 line of code if I can use jQuery.

我的服务的某些用户已经在其页面上使用jQuery(或Prototype等),因此,如果我包含jQuery,将会发生冲突.因为会有版本差异,所以我不想使用它们的jQuery选择器,以防jQuery存在.

Some of the users of my service already uses jQuery (or Prototype etc.) on their pages, so if I include jQuery there will be a conflict. Because there will be version differences, I don't want to use their jQuery selectors, methods either in case jQuery exists.

请记住,我无法控制他们的页面,如何包含jQuery并避免冲突?

Keeping in mind that I have no control over their pages, how can I include jQuery and avoid conflict?

推荐答案

大多数情况下,我需要选择器,所以有一天我偶然发现了它:

Mostly I needed selectors, so the other day I stumbled onto this: Sizzle, A pure-JavaScript CSS selector engine designed to be easily dropped in to a host library.

它可用于避免与任何其他Sizzle实例冲突.我很高兴找到了这个解决方案.

It can be used to avoid conflicts with any other Sizzle instances. I am very happy that I found this solution.

这篇关于在同一页面上使用不同版本的jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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