gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 08:34:48 25 4
gpt4 key购买 nike

我需要能够支持 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 $

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

这确实取决于使用 document.id 的 selectivzr 本身而不是 $ - document.id是 Mootools 调用“Mootools $”的替代方式'

关于javascript - 如何防止使用 selectvizr 时 mootools 和 jquery 之间的冲突?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44553944/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com