Javascript无法在IE中提供正确的输出 //如果您想要不同的版本,可以在此处进行编辑 //Base32实现 变量字母表='ABCDEFGHIJKLMNOPQRSTUVWXYZ012345' /** *建立一个查找表并记录它 * *返回将角色映射到其角色的对象 *字节值。 */ var lookup=函数(){ 变量表={} //颠倒“字母表” 对于(变量i=0;i跳过 跳过+=5 如果(跳过>=8){ //我们有足够的钱生产产量 this.output+=String.fromCharCode(字节) 跳过-=8 如果(跳过>0)字节=(val>3]:“”)+(检查?“$”:“”) this.output='' 返回输出 } } Decoder.prototype.update=函数(输入,刷新){ 对于(变量i=0;i

Javascript无法在IE中提供正确的输出 //如果您想要不同的版本,可以在此处进行编辑 //Base32实现 变量字母表='ABCDEFGHIJKLMNOPQRSTUVWXYZ012345' /** *建立一个查找表并记录它 * *返回将角色映射到其角色的对象 *字节值。 */ var lookup=函数(){ 变量表={} //颠倒“字母表” 对于(变量i=0;i跳过 跳过+=5 如果(跳过>=8){ //我们有足够的钱生产产量 this.output+=String.fromCharCode(字节) 跳过-=8 如果(跳过>0)字节=(val>3]:“”)+(检查?“$”:“”) this.output='' 返回输出 } } Decoder.prototype.update=函数(输入,刷新){ 对于(变量i=0;i,javascript,internet-explorer,Javascript,Internet Explorer,Internet Explorer的JScript引擎不支持对字符串常量的数组访问。您必须将alphabet[i]替换为alphabet.charAt(i)让它工作起来。虽然我认为微软已经解决了这个问题,但我可能错了/太有希望了。在IE9和IE8中工作得很好-我假设你使用的是IE7?解决方案=升级浏览器。给大家一个建议:@Neurofluxation:OP可能能够更新他/她的浏览器,但不能更新客户端的浏览器。我完全理解所有的实现都支持必须处理较旧的引擎,但是.charAt的挫折感,而且您不必“强

Internet Explorer的JScript引擎不支持对字符串常量的数组访问。您必须将
alphabet[i]
替换为
alphabet.charAt(i)
让它工作起来。虽然我认为微软已经解决了这个问题,但我可能错了/太有希望了。

在IE9和IE8中工作得很好-我假设你使用的是IE7?解决方案=升级浏览器。给大家一个建议:@Neurofluxation:OP可能能够更新他/她的浏览器,但不能更新客户端的浏览器。我完全理解所有的实现都支持必须处理较旧的引擎,但是
.charAt
的挫折感,而且您不必“强制”用户需要离开阴暗面,即IET这可能是一台使用Neuro的最新修补程序的机器……我在一台使用IE8和IIRC IE9的旧机器上对此进行了测试,结果表明它不起作用。@Omair:正如官方参考明确指出,字符串中字符的数组式访问是ECMA5功能,IE8目前不支持这一功能l、 并且在IE9中有bug(例如,严格模式)
    <script>
// This would be the place to edit if you want a different
// Base32 implementation

var alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ012345'


/**
 * Build a lookup table and memoize it
 *
 * Return an object that maps a character to its
 * byte value.
 */

var lookup = function() {
    var table = {}
    // Invert 'alphabet'
    for (var i = 0; i < alphabet.length; i++) {
        table[alphabet[i]] = i
    }

    lookup = function() { return table }
    return table
}


// Functions analogously to Encoder

function Decoder() {
    var skip = 0 // how many bits we have from the previous character
    var byte = 0 // current byte we're producing

    this.output = ''

    // Consume a character from the stream, store
    // the output in this.output. As before, better
    // to use update().
    this.readChar = function(char) {
        if (typeof char != 'string'){
            if (typeof char == 'number') {
                char = String.fromCharCode(char)
            }
        }
        //char = char.toLowerCase()
        var val = lookup()[char]
        if (typeof val == 'undefined') {
            // character does not exist in our lookup table
            return // skip silently. An alternative would be:
            // throw Error('Could not find character "' + char + '" in lookup table.')
        }
        val <<= 3 // move to the high bits
        byte |= val >>> skip
        skip += 5
        if (skip >= 8) {
            // we have enough to preduce output
            this.output += String.fromCharCode(byte)
            skip -= 8
            if (skip > 0) byte = (val << (5 - skip)) & 255
            else byte = 0
        }

    }

    this.finish = function(check) {
        var output = this.output + (skip < 0 ? alphabet[bits >> 3] : '') + (check ? '$' : '')
        this.output = ''
        return output
    }
}

Decoder.prototype.update = function(input, flush) {
    for (var i = 0; i < input.length; i++) {
        this.readChar(input[i])
    }
    var output = this.output
    this.output = ''
    if (flush) {
      output += this.finish()
    }
    return output
}

/** Convenience functions
 *
 * These are the ones to use if you just have a string and
 * want to convert it without dealing with streams and whatnot.
 */


// Base32-encoded string goes in, decoded data comes out.
function decode(input) {
    var decoder = new Decoder()
    var output = decoder.update(input.split("").reverse().join("")+'A', true)
    return output

}

function toHex(str) {
    var hex = '';
    for(var i=0;i<str.length;i++) {
       //hex += ''+("00" + str.charCodeAt(i).toString(16)).substr(-2);
       hex += str.charCodeAt(i).toString(16);
       }
    return hex;
}

convertHex = toHex(decode('A0C4KB'));
alert(convertHex);
</script>