简体   繁体   English

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

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

I need to be able to support all CSS3 pseudo-classes and attribute selectors in Internet Explorer 6-8. 我需要能够在Internet Explorer 6-8中支持所有CSS3伪类和属性选择器。 The polyfill called selectivizr allows you to do this. 名为selectivizr的polyfill允许您执行此操作。 It needs a javascript library such as jquery or mootools to work. 它需要一个JavaScript库(例如jquery或mootools)才能工作。 The problem is that while selectivizr supports all the pseudo-classes and attribute selectors with mootools, as many as 11 of them are either not recognized or not supported with jquery. 问题是,尽管selectivizr使用mootools支持所有伪类和属性选择器,但jquery最多无法识别11个伪类和属性选择器。 So although I have never used mootools in my life I am forced to add it to my webpage as an external script along with selectivizr in the conditional comments to detect if the webpage has been accessed from Internet Explorer 6-8 or not. 因此,尽管我一生中从未使用过Mootools,但我还是被迫将其作为外部脚本与条件注释中的selectivizr一起添加到我的网页中,以检测是否已从Internet Explorer 6-8访问该网页。

Like this: 像这样:

<!--[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]-->

The problem is that mootools and jquery have been known to conflict with each other. 问题是已知mootools和jquery会发生冲突。 My webpage has lots of jquery all over it. 我的网页上遍布着许多jquery。 Editing it all using jQuery.noConflict() is not really an option nor is wrapping all of it between 使用jQuery.noConflict()对其进行编辑实际上不是一个选择,也不会在两者之间包装所有内容

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

    })
}(jQuery))

Plus I don't know if so but the presence of more than one javascript libraries that selectivizr uses may cause problems with the functionality of selectivizr itself. 另外,我不知道是否可以,但是selectivizr使用的多个JavaScript库的存在可能会导致selectivizr本身的功能出现问题。 I think what I need to do is add some mootools code to my webpage to prevent it from conflicting with jquery and at the same time make sure that selectivizr is not detected by jquery and is only able to respond to mootools. 我认为我需要做的是向我的网页添加一些mootools代码,以防止它与jquery冲突,同时确保jquery未检测到selectivizr,并且只能响应mootools。 But since I have never used mootools I don't know how to do this. 但是由于我从未使用过mootools,所以我不知道该怎么做。 Can anyone help? 有人可以帮忙吗?

PS I don't have Internet Explorer 6-8 so I can't test this so please be careful and responsible if you give an answer. PS:我没有Internet Explorer 6-8,所以我无法测试它,因此如果您给出答案,请当心并负责。

Mootools doesn't claim the $ if something else has already defined it. 如果已经有其他定义,Mootools不会要求$ So if you make sure jQuery is loaded before Mootools the $ will still be a jQuery $ 因此,如果您确定在Mootools之前加载了jQuery,则$将仍然是jQuery $

(ie: keep the jquery <script> tag in the <head> , and don't use async or defer attributes) (即:将jquery <script>标记保留在<head> ,并且不要使用asyncdefer属性)

This does depend on selectivzr itself using document.id instead of $ - document.id is Mootools' alternative way of invoking the 'Mootools $ ' 这不使用依赖于selectivzr本身document.id代替$ - document.id是Mootools的Mootools的另类调用的方式‘ $

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM