Is it possible to use mootools and jQuery both together

后端 未结 2 1348
[愿得一人]
[愿得一人] 2021-01-20 04:07

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?

2条回答
  •  北荒
    北荒 (楼主)
    2021-01-20 04:49

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

    
    

    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);
    

    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.

提交回复
热议问题