jquery が IE8 ブラウザと互換性がない場合はどうすればよいですか?

coldplay.xixi
リリース: 2023-01-04 09:37:56
オリジナル
2448 人が閲覧しました

jquery 互換性は、ie8 ブラウザー ソリューションをサポートしていません。 1. IE8 のみが認識できるステートメント [] は認識できます。 IE8 モードで互換性のある操作を実行する場合に使用される; 2. forEach をサポートしていないブラウザーにカスタムの forEach メソッドを追加します。

jquery が IE8 ブラウザと互換性がない場合はどうすればよいですか?

このチュートリアルの動作環境: Windows7 システム、jquery3.2.1 バージョン、DELL G3 コンピューター。

推奨: jquery ビデオ チュートリアル

ie8 ブラウザーをサポートしない jquery の互換性に対する解決策:

1、IE8 は jQuery のバージョンをサポートしていません。

IE ブラウザのバージョンを確認して、対応するバージョンの jQuery をロードします。

ステートメント 互換性のある操作を IE8 モードで実行できます。コードは次のとおりです。

<script type="text/javascript" src="<%=path%>/js/jquery-3.1.1.min.js"></script>
<!--[if IE 8]>
<script type="text/javascript" src="<%=path%>/js/jquery-1.9.1.min.js"></script>
<![endif]-->
ログイン後にコピー

このように、IE8 に切り替えると、下位バージョンの jQuery が上位バージョンの jQuery を上書きします。 IE8 で一部の要素のスタイルを調整する必要がある場合は、JS コードをページの下部に配置することが最善です (そして、インライン スタイルがあるかどうかに注意してください)。そうしないと、動的に読み込まれる一部のコンテンツに設定されたスタイルが適用されない可能性があります。有効になります。

2. IE8 は forEach ソリューションをサポートしていません

forEach をサポートしていないブラウザーにカスタムの forEach メソッドを追加します

コードは次のとおりです。

if (typeof Array.prototype.forEach != &#39;function&#39;) {
    Array.prototype.forEach = function (callback) {
        for (var i = 0; i < this.length; i++) {
            callback.apply(this, [this[i], i, this]);
        }
    };
}
ログイン後にコピー

インポートされた jQuery プラグインの場合、このコードをプラグイン コンテンツの先頭に配置すると、IE8 で forEach メソッドが実行されたときにエラーが報告されなくなります。

3. IE8 はマップ ソリューションをサポートしていません

カスタム forEach メソッドを追加

if (!Array.prototype.map) {
    Array.prototype.map = function(callback, thisArg) {
        var T, A, k;
        if (this == null) {
            throw new TypeError(" this is null or not defined");
        }
        // 1. Let O be the result of calling ToObject passing the |this| value as the argument.
        var O = Object(this);
        // 2. Let lenValue be the result of calling the Get internal method of O with the argument "length".
        // 3. Let len be ToUint32(lenValue).
        var len = O.length >>> 0;
        // 4. If IsCallable(callback) is false, throw a TypeError exception.
        // See: http://es5.github.com/#x9.11
        if (typeof callback !== "function") {
            throw new TypeError(callback + " is not a function");
        }
        // 5. If thisArg was supplied, let T be thisArg; else let T be undefined.
        if (thisArg) {
            T = thisArg;
        }
        // 6. Let A be a new array created as if by the expression new Array(len) where Array is
        // the standard built-in constructor with that name and len is the value of len.
        A = new Array(len);
        // 7. Let k be 0
        k = 0;
        // 8. Repeat, while k < len
        while(k < len) {
            var kValue, mappedValue;
            // a. Let Pk be ToString(k).
            //   This is implicit for LHS operands of the in operator
            // b. Let kPresent be the result of calling the HasProperty internal method of O with argument Pk.
            //   This step can be combined with c
            // c. If kPresent is true, then
            if (k in O) {
                // i. Let kValue be the result of calling the Get internal method of O with argument Pk.
                kValue = O[ k ];
                // ii. Let mappedValue be the result of calling the Call internal method of callback
                // with T as the this value and argument list containing kValue, k, and O.
                mappedValue = callback.call(T, kValue, k, O);
                // iii. Call the DefineOwnProperty internal method of A with arguments
                // Pk, Property Descriptor {Value: mappedValue, : true, Enumerable: true, Configurable: true},
                // and false.
                // In browsers that support Object.defineProperty, use the following:
                // Object.defineProperty(A, Pk, { value: mappedValue, writable: true, enumerable: true, configurable: true });
                // For best browser support, use the following:
                A[ k ] = mappedValue;
            }
            // d. Increase k by 1.
            k++;
        }
        // 9. return A
        return A;
    };
}
ログイン後にコピー

関連する無料学習の推奨事項:js ビデオ チュートリアル

以上がjquery が IE8 ブラウザと互換性がない場合はどうすればよいですか?の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

関連ラベル:
ソース:php.cn
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!