Javascript Jquery和Mootools、.noConflict失败

Javascript Jquery和Mootools、.noConflict失败,javascript,mootools,jquery,Javascript,Mootools,Jquery,我有一个需要使用mootools日历的应用程序,但是,我使用jquery作为我的主要应用程序结构 一旦我将mootools与jquery结合在一起,这两种工具都不起作用,当我只有一种工具时,它们就可以正常工作。我做了一些研究,说我可以使用一种叫做.noconflict的方法,虽然我已经尝试过了,但我还没有用它来解决我的问题。也许有人能更好地向我解释在哪里进行实际的.无冲突的通话,也许能帮助我使这项工作正常进行 谢谢 <script src="//ajax.googleapis.com/aj

我有一个需要使用mootools日历的应用程序,但是,我使用jquery作为我的主要应用程序结构

一旦我将mootools与jquery结合在一起,这两种工具都不起作用,当我只有一种工具时,它们就可以正常工作。我做了一些研究,说我可以使用一种叫做.noconflict的方法,虽然我已经尝试过了,但我还没有用它来解决我的问题。也许有人能更好地向我解释在哪里进行实际的.无冲突的通话,也许能帮助我使这项工作正常进行

谢谢

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        var fixHeight = function () {
                var gutter = 50;
                var newHeight = $(window).height() - (gutter*2);
                $('#container').height(newHeight);
        }
        $(function(){ 

            fixHeight();
            $('ul#nav li.item').each(function(index) {
                if ($(this).attr("name") == "media") {
                    $(this).attr("id","active");
                }
            });
            $('input').focus(function() {
                $(this).attr("value","");
            }).blur(function() {
                $(this).attr("value",$(this).attr("original-value"));
            });

            $(window).resize(function() {
                fixHeight();
            }).load(function() {
                fixHeight();
            });

        });  
     </script>
     <script type="text/javascript" src="http://taptouchclick.com/js/mootools-1.2.4-core-yc.js"></script>
     <script type="text/javascript">
        window.addEvent('domready', function(){
             var smoothCalendar = new SmoothCalendar("calendar");
        });
    </script>

var fixHeight=函数(){
var=50;
var newHeight=$(窗口).height()-(檐槽*2);
$(“#容器”)。高度(新高度);
}
$(函数(){
固定高度();
$('ul#nav li.item')。每个(功能(索引){
if($(this.attr(“name”)=“media”){
$(this.attr(“id”,“active”);
}
});
$('input').focus(函数(){
$(this.attr(“value”,”);
}).blur(函数(){
$(this.attr(“值”),$(this.attr(“原始值”);
});
$(窗口)。调整大小(函数(){
固定高度();
}).load(函数(){
固定高度();
});
});  
addEvent('domready',function(){
var smoothCalendar=新的smoothCalendar(“日历”);
});

如果您只需拨打:

jQuery.noConflict();
…在包含Mootools JS文件之前

然后,您可以通过使用
jQuery
而不是
$
来使用jQuery函数。例如:

jQuery('.selector').hide();  // instead of $('.selector').hide();

如果您只是打电话给:

jQuery.noConflict();
…在包含Mootools JS文件之前

然后,您可以通过使用
jQuery
而不是
$
来使用jQuery函数。例如:

jQuery('.selector').hide();  // instead of $('.selector').hide();

是的,
noConflict
方法应该可以工作,但是如果它不能工作,或者如果您想用另一种方式工作,则应该将脚本封装在自调用函数中,并将参数设置为主库对象:

(function($){
    // al your jquery logic here
    alert($ instanceof jQuery);
})(jQuery)

在这之后,您应该包括下一个库(在您的例子中是MooTools)并正常编写脚本,或者——可以肯定的是——您也可以将MooTools逻辑封装到函数中。

是的,
noConflict
方法应该可以工作,但是如果它不能工作,或者您想用另一种方式来做,应将脚本封装在自调用函数中,并将参数设置为主库对象:

(function($){
    // al your jquery logic here
    alert($ instanceof jQuery);
})(jQuery)

在此之后,您应该包括下一个库(在您的例子中是MooTools)并正常编写脚本,或者——非常肯定地——您也可以将MooTools逻辑封装到函数中。

您还可以通过DOM就绪事件将
$
传递回:

$.noConflict();

// Non-jQuery code goes here

jQuery(document).ready(function($) {
    // You can now use the dollar sign safely inside of this function
}

您还可以通过DOM就绪事件将
$
传递回:

$.noConflict();

// Non-jQuery code goes here

jQuery(document).ready(function($) {
    // You can now use the dollar sign safely inside of this function
}