2011-05-21 86 views
0

我有一个需要使用mootools日历的应用程序,但是,我为我的主应用程序结构使用了jquery。Jquery和Mootools,.noConflict失败

只要我有jQuery的mootools,既不工作,当我只有一个,他们工作正常。我做了一些研究,说我可以使用一种名为.noconflict的方法,虽然我已经尝试过,但还没有得到它来解决我的问题。也许有人可以更好地向我解释在哪里做实际的.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> 

回答

1

你应该罚款,如果你简单地调用:

jQuery.noConflict(); 

...包括MooTools的JS文件之前。

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

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

感谢,伟大的工作:d – willium 2011-05-21 07:11:37

2

肯定的,noConflict方法应该可行,但如果没有,或者如果你想这样做的另一种方式,你应该用参数被设置为封装在自调用函数的脚本主库对象:

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

在这之后,你应该包括未来图书馆(在你的情况MooTools的),通常写剧本,或者 - 很肯定 - 你可以封装MooTools的逻辑函数,如好。

0

您也可以通过$回到通过DOM就绪事件:

$.noConflict(); 

// Non-jQuery code goes here 

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