>  기사  >  웹 프론트엔드  >  jquery가 IE8 브라우저와 호환되지 않으면 어떻게 해야 합니까?

jquery가 IE8 브라우저와 호환되지 않으면 어떻게 해야 합니까?

coldplay.xixi
coldplay.xixi원래의
2020-12-24 10:12:242449검색

IE8 브라우저를 지원하지 않는 jquery 호환성을 위한 솔루션: 1. IE8에서만 인식되는 [266c419352a525843049eb7155ebf872]는 IE8 모드에서 일부 호환 작업을 수행할 수 있습니다. 2. forEach를 지원하지 않는 브라우저에 대한 사용자 정의 forEach 메소드를 추가하십시오.

jquery가 IE8 브라우저와 호환되지 않으면 어떻게 해야 합니까?

이 튜토리얼의 운영 환경: windows7 시스템, jquery3.2.1 버전, DELL G3 컴퓨터.

권장: jquery 비디오 튜토리얼

IE8 브라우저를 지원하지 않는 jquery 호환성을 위한 솔루션:

1 IE8은 jQuery 버전 솔루션을 지원하지 않습니다

IE 버전을 확인하여 해당 버전을 로드합니다. 브라우저 jQuery

  IE8 모드에서 일부 호환 작업을 수행하려면 IE8만 1b771f47d72d900ba74308aee59557f0 문을 사용하세요. 코드는 다음과 같습니다.

<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 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.