• <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
  • 兼容低版本 IE 的 JScript 5.5 實現

    發表于:2007-06-21來源:作者:點擊數: 標簽:
    IE 5.5 中的 JScript 版本是 5.5 版,它比以前版本的 JScript 中多了如數組的 push、pop、shift、unshift 方法和 encodeURI、decodeURI 等一些重要的函數。而這些增加的內容在目前其他瀏覽器(如 Moziila/Firefox 和 Opera)上也同樣支持。 因此目前 開發 網

       

    IE 5.5 中的 JScript 版本是 5.5 版,它比以前版本的 JScript 中多了如數組的 push、pop、shift、unshift 方法和 encodeURI、decodeURI 等一些重要的函數。而這些增加的內容在目前其他瀏覽器(如 Moziila/Firefox 和 Opera)上也同樣支持。

    因此目前開發網站一般對于 IE 瀏覽器只能兼容到 5.5 版,而對于更低版本的 IE(如 IE 5、IE 4 等),則不再去考慮了。雖然這些低版本的 IE 瀏覽器目前已經不是主流,但如果能夠不需要修改現有代碼就能夠兼容它們的話,倒是也可以考慮。因此我做了這個兼容低版本 IE 的 JScript 5.5 實現。當然它不可能完全兼容 JScript 5.5,但對于最常用的一些方法,都已經實現了。

    該庫使用非常簡單,只需要在網頁的 head 部分加入:

    <script type="text/javascript" src="iecompat.js"></script>

    就可以了。

    完全實現的:

    • Array 對象中:
      • push 方法
      • pop 方法
      • shift 方法
      • unshift 方法
      • splice 方法
    • Date 對象中:
      • toDateString 方法
      • toTimeString 方法
      • toLocaleDateString 方法
      • toLocaleTimeString 方法
    • Function 對象中:
      • apply 方法
      • call 方法
    • Global 對象中:
      • undefined 屬性
      • encodeURI 方法
      • encodeURIComponent 方法
      • decodeURI 方法
      • decodeURIComponent 方法
    • Number 對象中:
      • toExponential 方法
      • toFixed 方法
      • toPrecision 方法

    對于錯誤處理,IE 5(JScript 5)中已經有了 try…catch 和 throw 語句,因此 decodeURI、decodeURIComponent、toExponential、toFixed、toPrecision、apply 如果出現運行期錯誤,在 IE 5 上會拋出跟 IE 5.5+ 中一樣的錯誤信息,但是因為 IE 4 沒有錯誤處理語句,如果上述函數出現運行期錯誤,將會返回 null。注意上面說的運行期錯誤,不是指上述函數實現中的錯誤,而是指在這些函數正常工作的情況下應該出現的錯誤。

    其中 Function 的 apply 函數的實現參考了http://www.openjsan.org/doc/a/ad/adamk/Upgrade/0.04/lib/Upgrade/Function/apply.html
    這段程序。

    不完全實現的:

    • Error 對象
    • Object 對象中:
      • isPrototypeOf 方法
      • hasOwnProperty 方法
      • propertyIsEnumerable 方法
    • String 對象中:
      • toLocaleLowerCase 方法
      • toLocaleUpperCase 方法
      • localeCompare 方法

    因為 IE 4 不具備錯誤處理語句,因此 Error 對象在 IE 4 上并不具備 IE 5 以上 Error 對象應具有的功能,因此它對于 IE 4 的實現只能保證你在訪問或創建它時不會出錯。

    Object 中的 isPrototypeOf、hasOwnProperty 和 propertyIsEnumerable 方法只是做了模擬實現,其返回值并非總是正確。

    String 對象中的 toLocaleLowerCase、toLocaleUpperCase 和 localeCompare 方法實際上并沒有考慮本地字符集,但在大部分系統上它還是工作正常的。

    完全沒有實現的:

    • 正則表達式對象中擴充的屬性和限定符

    .
    ———————————————–
    如果你想測試低版本的 IE 瀏覽器上的效果,又沒有安裝低版本的 IE 瀏覽器,可以使用這個包:ie_all.zip。這里面都是不需要安裝的 IE,直接釋放壓縮包到一個目錄下,就可以運行了。如果你是 win9x 系統,可以到這里下載 win9x 版的 standalone IE。

    /* iecompat.js
    *
    * Copyright Ma Bingyao <andot@ujn.edu.cn>
    * Version: 1.1
    * LastModified: 2006-02-10
    * This library is free.  You can redistribute it and/or modify it.
    * http://www.coolcode.cn/?p=126
    */
     
    /*@clearcase/" target="_blank" >cc_on @*/
     
    /*@if (@_jscript_version < 5)
     
    function Error(number, description) {
        if (!number) this.number = 0;
        else this.number = number;
        if (!description) this.description = "";
        else this.description = description;
    }
     
    @end @*/
     
    /*@if (@_jscript_version < 5.5)
     
    // this return value was not very correct
    Object.prototype.isPrototypeOf = function (o) {
        return (this.constructor == o.constructor);
    }
     
    // this return value was not very correct
    Object.prototype.hasOwnProperty = function (proName) {
        return (typeof(eval("this." + proName)) != "undefind");
    }
     
    Object.prototype.propertyIsEnumerable = function (proName) {
        for (var o in this) {
            if ((proName == o.toString()) &&
               (proName != "propertyIsEnumerable") &&
               (proName != "isPrototypeOf") &&
               (proName != "hasOwnProperty")) return true;
        }
        return false;
    }
     
    Error.prototype.message = "";
    Error.prototype.name = "Error";
     
    Date.prototype.toDateString = function () {
        var s = this.toString().split(' ');
        return [s[0], s[1], s[2], s[5]].join(' ');
    }
     
    Date.prototype.toTimeString = function () {
        var s = this.toString().split(' ');
        return [s[3], s[4]].join(' ');
    }
     
    Date.prototype.toLocaleDateString = function () {
        return this.toLocaleString().split(' ')[0];
    }
     
    Date.prototype.toLocaleTimeString = function () {
        return this.toLocaleString().split(' ')[1];
    }
     
    String.prototype.toLocaleLowerCase = function () {
        return this.toLowerCase();
    }
     
    String.prototype.toLocaleUpperCase = function () {
        return this.toUpperCase();
    }
     
    String.prototype.localeCompare = function (str) {
        if (this > str) return 1;
        if (this < str) return -1;
        return 0;
    }
     
    Number.prototype.toExponential = function (n) {
        function repeat(s, n) {
            var out = "";
            for (var i = 0; i < n; i++) {
                out += s;
            }
            return out;
        }
        if (!n) {
            n = 0;
        }
        else {
            n = parseInt(n);
            if (n < 0 || n > 20) {
                @if (@_jscript_version < 5)
                    return null;
                @else
                    var e = new Error(-2146823262, "The number of fractional digits is out of range");
                    e.name = "RangeError";
                    e.message = e.description;
                    throw(e);
                @end
            }
        }
        var s, d, e, len;
        s = this.toString().split("e");
        d = parseFloat(s[0]);
        e = 0;
        if (typeof(s[1]) != "undefined") {
            e = parseInt(s[1]);
        }
        s = d.toString().split(".");
        if (typeof(s[1]) != "undefined") {
            e = e - s[1].length;
            d = s[0] + s[1];
            d = d.replace(/^0+/g, "");
            if (d == "") d = "0";
        }
        s = d.toString();
        len = s.length - 1;
        e += len;
        if (len < n) {
            s += repeat("0", n - len);
        }
        else if (len > n) {
            s = Math.round(parseFloat("." + s) * Math.pow(10, n + 1)).toString();
            if ((s.length - 1) > n) {
                e += 1;
                s = Math.round(parseFloat("." + s) * Math.pow(10, n + 1)).toString();
            }
        }
        if (e >= 0) {
            e = "+" + e;
        }
        if (n == 0) {
            return s + "e" + e;
        }
        else {
            return s.substr(0, 1) + "." + s.substr(1) + "e" + e;
        }
    }
     
    Number.prototype.toFixed = function (n) {
        function repeat(s, n) {
            var out = "";
            for (var i = 0; i < n; i++) {
                out += s;
            }
            return out;
        }
        if (!n) {
            n = 0;
        }
        else {
            n = parseInt(n);
            if (n < 0 || n > 20) {
                @if (@_jscript_version < 5)
                    return null;
                @else
                    var e = new Error(-2146823262, "The number of fractional digits is out of range");
                    e.name = "RangeError";
                    e.message = e.description;
                    throw(e);
                @end
            }
        }
        var s, d, e, len;
        s = this.toString().split("e");
        d = parseFloat(s[0]);
        e = 0;
        if (typeof(s[1]) != "undefined") {
            e = parseInt(s[1]);
        }
        s = d.toString().split(".");
        if (typeof(s[1]) != "undefined") {
            e = e - s[1].length;
            d = s[0] + s[1];
            d = d.replace(/^0+/g, "");
            if (d == "") d = "0";
        }
        s = d.toString();
        len = s.length - 1;
       
        if (e >= 0) {
            s += repeat("0", e);
            if (n > 0) {
                s += "." + repeat("0", n);
            }
        }
        else if (-e <= n) {
            s = repeat("0", 1 - e - s.length) + s;
            s = s.substr(0, s.length + e) + "." + s.substr(s.length + e) + repeat("0", n + e);
        }
        else {
            s = repeat("0", 1 - e - s.length) + s;
            d = parseFloat(s.substr(0, s.length + e) + "." + s.substr(s.length + e));
            s = Math.round(d * Math.pow(10, n)).toString();
            if (n > 0) {
                s = repeat("0", n - s.length + 1) + s;
                s = s.substr(0, s.length - n) + "." + s.substr(s.length - n);
            }
        }
        return s;
    }
     
    Number.prototype.toPrecision = function (n) {
        function repeat(s, n) {
            var out = "";
            for (var i = 0; i < n; i++) {
                out += s;
            }
            return out;
        }
        if (typeof(n) == "undefined") {
            return this.toString();
        }
        else {
            n = parseInt(n);
            if (n < 1 || n > 21) {
                @if (@_jscript_version < 5)
                    return null;
                @else
                    var e = new Error(-2146823262, "The precision is out of range");
                    e.name = "RangeError";
                    e.message = e.description;
                    throw(e);
                @end
            }
        }
        if (this.valueOf() == 0) {
            if (n == 1) return "0";
            return "0." + repeat("0", n - 1);
        }
        var s, d, e, len;
        s = this.toString().split("e");
        d = parseFloat(s[0]);
        e = 0;
        if (typeof(s[1]) != "undefined") {
            e = parseInt(s[1]);
        }
        s = d.toString().split(".");
        if (typeof(s[1]) != "undefined") {
            e = e - s[1].length;
            d = s[0] + s[1];
            d = d.replace(/^0+/g, "");
            if (d == "") d = "0";
        }
        s = d.toString();
        len = s.length;
        d = parseFloat("." + s) * Math.pow(10, n);
        s = Math.round(d).toString();
        if (s.length > parseInt(d).toString().length) {
            e++;
            s = s.slice(0, -1);
        }
        e += len - s.length;
        len = s.length;
        e += len - 1;
     
        if (e < n && e > -7) {
            if ((e < n - 1) && (e > 0)) {
                s = s.substr(0, e + 1) + "." + s.substr(e + 1);
            }
            else if (e <= 0) {
                s = repeat("0", - e) + s;
                s = s.substr(0, 1) + "." + s.substr(1);
            }
        }
        else {
            if (len < n) {
                s += repeat("0", n - len);
            }
            if (e >= 0) {
                e = "+" + e;
            }
            if (n == 1) {
                s += "e" + e;
            }
            else {
                s = s.substr(0, 1) + "." + s.substr(1) + "e" + e;
            }
        }
        return s;
    }
     
    var undefined;
     
    function encodeURI(str) {
        var l = ['%00', '%01', '%02', '%03', '%04', '%05', '%06',
                 '%07', '%08', '%09', '%0A', '%0B', '%0C', '%0D',
                 '%0E', '%0F', '%10', '%11', '%12', '%13', '%14',
                 '%15', '%16', '%17', '%18', '%19', '%1A', '%1B',
                 '%1C', '%1D', '%1E', '%1F', '%20', '!', '%22',
                 '#', '$', '%25', '&', "'", '(', ')', '*', '+', ',',
                 '-', '.', '/', '0', '1', '2', '3', '4', '5', '6',
                 '7', '8', '9', ':', ';', '%3C', '=', '%3E', '?',
                 '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
                 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
                 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '%5B', '%5C',
                 '%5D', '%5E', '_', '%60', 'a', 'b', 'c', 'd', 'e',
                 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
                 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
                 'z', '%7B', '%7C', '%7D', '~', '%7F'];
        var out, i, len, c;
     
        out = "";
        len = str.length;
        for(i = 0; i < len; i++) {
            c = str.charCodeAt(i);
            if (c <= 0x007F) {
                out += l[c];
            }
            else if (c > 0x07FF) {
                out += '%' + (0xE0 | ((c >> 12) & 0x0F)).toString(16).toUpperCase();
                out += '%' + (0x80 | ((c >>  6) & 0x3F)).toString(16).toUpperCase();
                out += '%' + (0x80 | ((c >>  0) & 0x3F)).toString(16).toUpperCase();
            }
            else {
                out += '%' + (0xC0 | ((c >>  6) & 0x1F)).toString(16).toUpperCase();
                out += '%' + (0x80 | ((c >>  0) & 0x3F)).toString(16).toUpperCase();
            }
        }
        return out;
    }
     
    function encodeURIComponent(str) {
        var l = ['%00', '%01', '%02', '%03', '%04', '%05', '%06',
                 '%07', '%08', '%09', '%0A', '%0B', '%0C', '%0D',
                 '%0E', '%0F', '%10', '%11', '%12', '%13', '%14',
                 '%15', '%16', '%17', '%18', '%19', '%1A', '%1B',
                 '%1C', '%1D', '%1E', '%1F', '%20', '!', '%22',
                 '%23', '%24', '%25', '%26', "'", '(', ')', '*', '%2B', '%2C',
                 '-', '.', '%2F', '0', '1', '2', '3', '4', '5', '6',
                 '7', '8', '9', '%3A', '%3B', '%3C', '%3D', '%3E', '%3F',
                 '%40', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
                 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
                 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '%5B', '%5C',
                 '%5D', '%5E', '_', '%60', 'a', 'b', 'c', 'd', 'e',
                 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
                 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
                 'z', '%7B', '%7C', '%7D', '~', '%7F'];
        var out, i, len, c;
     
        out = "";
        len = str.length;
        for(i = 0; i < len; i++) {
            c = str.charCodeAt(i);
            if (c <= 0x007F) {
                out += l[c];
            }
            else if (c > 0x07FF) {
                out += '%' + (0xE0 | ((c >> 12) & 0x0F)).toString(16).toUpperCase();
                out += '%' + (0x80 | ((c >>  6) & 0x3F)).toString(16).toUpperCase();
                out += '%' + (0x80 | ((c >>  0) & 0x3F)).toString(16).toUpperCase();
            }
            else {
                out += '%' + (0xC0 | ((c >>  6) & 0x1F)).toString(16).toUpperCase();
                out += '%' + (0x80 | ((c >>  0) & 0x3F)).toString(16).toUpperCase();
            }
        }
        return out;
    }
     
    function decodeURI(str) {
        function throwerror() {
            @if (@_jscript_version < 5)
                return null;
            @else
                var e = new Error(-2146823263, "The URI to be decoded is not a valid encoding");
                e.name = "URIError";
                e.message = e.description;
                throw(e);
            @end
        }
        function checkcode() {
            var d1, d2;
            d1 = str.charAt(i++);
            d2 = str.charAt(i++);
            if (isNaN(parseInt(d1, 16)) || isNaN(parseInt(d2, 16))) {
                return throwerror();
            }
            return parseInt(d1 + d2, 16);
        }
        function checkutf8() {
            var c = str.charCodeAt(i++);
            if (c == 37) {
                if ((c = checkcode()) == null) return null;
            }
            if ((c >> 6) != 2) {
                return throwerror();
            }
        }
        var out, i, len;
        var c, c2, c3;
     
        out = "";
        len = str.length;
        i = 0;
        while(i < len) {
            c = str.charCodeAt(i++);
            if (c == 37) {
                if ((c = checkcode()) == null) return null;
            }
            else {
                out += String.fromCharCode(c);
                continue;
            }
            switch(c) {
                case 35: case 36: case 38: case 43: case 44: case 47:
                case 58: case 59: case 61: case 63: case 64: {
                    if (str.charCodeAt(i - 3) == 37) {
                        out += str.substr(i - 3, 3);
                    }
                    else {
                        out += str.substr(i - 1, 1);
                    }
                    break;
                }
                default: {
                    switch(c >> 4) {
                        case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: {
                            // 0xxxxxxx
                            out += String.fromCharCode(c);
                            break;
                        }
                        case 12: case 13: {
                            // 110x xxxx   10xx xxxx
                            if ((c2 = checkutf8()) == null) return null;
                            out += String.fromCharCode(((c & 0x1F) << 6) | (c2 & 0x3F));
                            break;
                        }
                        case 14: {
                            // 1110 xxxx  10xx xxxx  10xx xxxx
                            if ((c2 = checkutf8()) == null) return null;
                            if ((c3 = checkutf8()) == null) return null;
                            out += String.fromCharCode(((c & 0x0F) << 12) |
                                        ((char2 & 0x3F) << 6) |
                                        ((char3 & 0x3F) << 0));
                            break;
                        }
                        default: {
                            out += String.fromCharCode(c);
                            file://return throwerror();
                        }
                    }
                }
            }
        }
        return out;
    }
     
    function decodeURIComponent(str) {
        function throwerror() {
            @if (@_jscript_version < 5)
                return null;
            @else
                var e = new Error(-2146823263, "The URI to be decoded is not a valid encoding");
                e.name = "URIError";
                e.message = e.description;
                throw(e);
            @end
        }
        function checkcode() {
            var d1, d2;
            d1 = str.charAt(i++);
            d2 = str.charAt(i++);
            if (isNaN(parseInt(d1, 16)) || isNaN(parseInt(d2, 16))) {
                return throwerror();
            }
            return parseInt(d1 + d2, 16);
        }
        function checkutf8() {
            var c = str.charCodeAt(i++);
            if (c == 37) {
                if ((c = checkcode()) == null) return null;
            }
            if ((c >> 6) != 2) {
                return throwerror();
            }
        }
        var out, i, len;
        var c, c2, c3;
     
        out = "";
        len = str.length;
        i = 0;
        while(i < len) {
            c = str.charCodeAt(i++);
            if (c == 37) {
                if ((c = checkcode()) == null) return null;
            }
            else {
                out += String.fromCharCode(c);
                continue;
            }
            switch(c >> 4) {
                case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: {
                    // 0xxxxxxx
                    out += String.fromCharCode(c);
                    break;
                }
                case 12: case 13: {
                    // 110x xxxx   10xx xxxx
                    if ((c2 = checkutf8()) == null) return null;
                    out += String.fromCharCode(((c & 0x1F) << 6) | (c2 & 0x3F));
                    break;
                }
                case 14: {
                    // 1110 xxxx  10xx xxxx  10xx xxxx
                    if ((c2 = checkutf8()) == null) return null;
                    if ((c3 = checkutf8()) == null) return null;
                    out += String.fromCharCode(((c & 0x0F) << 12) |
                                ((char2 & 0x3F) << 6) |
                                ((char3 & 0x3F) << 0));
                    break;
                }
                default: {
                    return throwerror();
                }
            }
        }
        return out;
    }
     
    Array.prototype.push = function () {
        var curlen = this.length;
        for (var i = 0; i < arguments.length; i++) {
            this[curlen + i] = arguments[i];
        }
        return this.length;
    }
     
    Array.prototype.pop = function () {
        var returnValue = this[this.length - 1];
        this.length--;
        return returnValue;
    }
     
    Array.prototype.shift = function () {
        var returnValue = this[0];
        for (var i = 1; i < this.length; i++) {
            this[i - 1] = this[i];
        }
        this.length--;
        return returnValue;
    }
     
    Array.prototype.unshift = function () {
        var curlen = this.length;
        var arglen = arguments.length;
        for (var i = curlen - 1; i >= 0 ; i--) {
            this[i + arglen] = this[i] ;
        }
        for (var i = 0; i < arglen; i++) {
            this[i] = arguments[i];
        }
        file://return this.length;  // return this value is Gecko/Opera implementation. but IE don't return anything.
    }
     
    Array.prototype.splice = function () {
        var start = arguments[0];
        var deleteCount = arguments[1];
        var len = arguments.length - 2;
        var returnValue = this.slice(start);
        for (var i = 0; i < len; i++) {
            this[start + i] = arguments[i + 2];
        }
        for (var i = 0; i < returnValue.length - deleteCount; i++) {
            this[start + len + i] = returnValue[deleteCount + i];
        }
        this.length = start + len + returnValue.length - deleteCount;
        returnValue.length = deleteCount;
        return returnValue;
    }
     
    Function.prototype.apply = function (o, p) {
        var ps = [];
        if (typeof(o) == "undefined") {
            var __$$apply$$__ = this;
            return eval('__$$apply$$__(' + ps.join(', ') + ');');
        }
        if (p) {
            if (typeof(p[0]) == "undefined") {
                @if (@_jscript_version < 5)
                    return null;
                @else
                    var e = new Error(-2146823260, "Array or arguments object expected");
                    e.name = "TypeError";
                    e.message = e.description;
                    throw(e);
                @end
            }
            for (var i = 0; i < p.length; i++) {
                ps[i] = 'p[' + i + ']';
            }
        }
        if ((typeof(o) == "object") || (typeof(o) == "function")) {
            o.__$$apply$$__ = this;
            var returnValue = eval('o.__$$apply$$__(' + ps.join(', ') + ');');
            o.__$$apply$$__ = null;
            return returnValue;
        }
        else {
            this.__$$apply$$__ = this;
            var returnValue = eval('this.__$$apply$$__(' + ps.join(', ') + ');');
            this.__$$apply$$__ = null;
            return returnValue;
        }
    }
     
    Function.prototype.call = function (o) {
        var ps = [];
        if (typeof(o) == "undefined") {
            var __$$call$$__ = this;
            return eval('__$$call$$__(' + ps.join(', ') + ');');
        }
        if (arguments.length > 1) {
            for (var i = 1; i < arguments.length; i++) {
                ps[i - 1] = 'arguments[' + i + ']';
            }
        }
        if ((typeof(o) == "object") || (typeof(o) == "function")) {
            o.__$$call$$__ = this;
            var returnValue = eval('o.__$$call$$__(' + ps.join(', ') + ');');
            o.__$$call$$__ = null;
            return returnValue;
        }
        else {
            this.__$$call$$__ = this;
            var returnValue = eval('this.__$$call$$__(' + ps.join(', ') + ');');
            this.__$$call$$__ = null;
            return returnValue;
        }
    }
     
    @end @*/

    原文轉自:http://www.kjueaiud.com

    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>