如何防止使用 selectvizr 时 mootools 和 jquery 之间的冲突?

How to prevent conflict between mootools and jquery for using selectvizr?

我需要能够支持 Internet Explorer 6-8 中的所有 CSS3 伪 类 和属性选择器。名为 selectivizr 的 polyfill 允许您执行此操作。它需要 javascript 库,例如 jquery 或 mootools 才能工作。问题在于,虽然 selectivizr 支持所有伪 类 和带有 mootools 的属性选择器,但其中多达 11 个不被识别或不被 jquery 支持。因此,尽管我一生中从未使用过 mootools,但我不得不将其作为外部脚本与条件注释中的 selectivizr 一起添加到我的网页中,以检测网页是否已从 Internet Explorer 6-8 访问过。

像这样:

<!--[if (gte IE 6)&(lte IE 8)]>
  <script type="text/javascript" src="mootools-core.js"></script>
  <script type="text/javascript" src="selectivizr.js"></script>
  <noscript><link rel="stylesheet" href="[fallback css]" /></noscript>
<![endif]-->

问题是 mootools 和 jquery 已知相互冲突。我的网页上有很多 jquery。使用 jQuery.noConflict() 全部编辑并不是真正的选择,也不是将所有内容都包装在

之间
(function ($) {
    // $ is actually jQuery here
    $(document).ready(function () {

    })
}(jQuery))

此外,我不知道是不是这样,但是 selectivizr 使用的多个 javascript 库的存在可能会导致 selectivizr 本身的功能出现问题。我想我需要做的是在我的网页中添加一些 mootools 代码,以防止它与 jquery 冲突,同时确保 selectivizr 未被 jquery 检测到并且只能响应到 mootools。但由于我从未使用过 mootools,所以我不知道该怎么做。有人可以帮忙吗?

P.S我没有Internet Explorer 6-8所以没法测试所以回答请谨慎负责

Mootools 不会声明 $ 如果其他东西已经定义了它。因此,如果您确保 jQuery 在 Mootools 之前加载,$ 仍将是 jQuery $

(即:在<head>中保留jquery <script>标签,不要使用asyncdefer属性)

这取决于 selectivzr 本身使用 document.id 而不是 $ - document.id 是 Mootools 调用 'Mootools $'

的替代方法