1

重複の可能性:
同じページで複数のバージョンの jQuery を使用できますか?

1.2.4 を使用している Web サイトに新しい JavaScript コードを追加します。追加するコードには 1.8.2 バージョンが必要です。

だから、これは私が持っているコードです:

var thisPageUsingOtherJSLibrary = false;

if (typeof jQuery == 'undefined' || jQuery.fn.jquery !== '1.8.2') {
    if (typeof $ == 'function') {
        thisPageUsingOtherJSLibrary = true;
    }

    function getScript(url, success) {
        var script = document.createElement('script');
        script.src = url;

        var head = document.getElementsByTagName('head')[0];

        done = false;
        script.onload = script.onreadystatechange = function () {
            if (!done && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) {
                done = true;
                success();
                script.onload = script.onreadystatechange = null;
                head.removeChild(script);
            };
        };

        head.appendChild(script);
    };

    getScript('http://code.jquery.com/jquery-1.8.2.min.js', function () {
        if (typeof jQuery !== 'undefined') {
            if (!thisPageUsingOtherJSLibrary) {
                jQuery(document).ready(function ($) {
                    initWithNewJquery($);
                });
            } else {
                var jQuery_1_8_2 = $.noConflict(true);
                jQuery_1_8_2(document).ready(function ($) {
                    initWithNewJquery($);
                });
            }
        }
    });

} else {
    jQuery(document).ready(function ($) {
        initWithNewJquery($);
    });
}

function initWithNewJquery($){

}

私が必要としているのは、コードを追加する Web サイトに古い jquery を使用することです。新しい関数/ハンドラーに新しい jquery を使用します ( function 内に追加されますinitWithNewJquery($))。

いくつかの理由で、私が書いたコードは間違っていると思います。また、このエラーが発生するためです。

TypeError: a.livequery is not a function

noConflict()では、ここで正しく使用するにはどうすればよいでしょうか。

4

0 に答える 0