How to encapsulate jQuery?

后端 未结 4 604
一整个雨季
一整个雨季 2021-01-14 03:46

Particularly I want to define local jQuery (var jQuery) where
jQuery should be stored (and also local $).

The problem is that jQuery operates directly with windo

4条回答
  •  日久生厌
    2021-01-14 04:20

    You can pass true to $.noconflict() to have jQuery remove all its variables from the global scope:

    (function($) {
        var jQuery = $.noconflict(true);
        // From there on, window.jQuery and window.$ are undefined.
        var $ = jQuery;
        // Do something with the local jQuery and $...
    })(jQuery);
    

提交回复
热议问题