是否可以同时使用mootools和jQuery [英] Is it possible to use mootools and jQuery both together

查看:72
本文介绍了是否可以同时使用mootools和jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须一起使用mootools和jquery文件.但是同时使用两者时会发生冲突.有什么解决方案可以避免这种冲突?

I have to use mootools and jquery files together. But there is a conflict occurs while using both together. Is there any solution to avoid this conflict?

推荐答案

是的,您必须在包含jQuery之后且包含Mootools之前包含此代码.

Yes, you'll have to include this code just after you include your jQuery and before you include Mootools.

<script>
    var j$ = jQuery.noConflict();
</script>

然后,您想用j$查找/替换所有jQuery $引用,最好使用大多数代码编辑器中提供的自动工具.

You'll then want to find/replace all jQuery $ references with j$, preferably using the automated tool found in most code editors.

您还有另一个选择,即闭包.如果我没记错的话,看起来会像这样:

You also have another option, a closure. It would look something like this, if I remember correctly:

(function($) {
  //jQuery stuff
})(jQuery);

您将要在此函数内移动所有现有代码.它的作用域是$变量,因此您可以像往常一样在闭包内使用jQuery进行业务,然后在其外部使用Mootools.

You'll want to move all your existing code inside this function. It scopes the $ variable so you can do business with jQuery as usual within the closure, then use Mootools outside of it.

这篇关于是否可以同时使用mootools和jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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