我使用以下函数将字符串编码为 base64:
encode: function(input) {
var output = "";
var chr1, chr2, chr3;
var enc1, enc2, enc3, enc4;
var i = 0;
do {
chr1 = input.charCodeAt(i++);
chr2 = input.charCodeAt(i++);
chr3 = input.charCodeAt(i++);
enc1 = chr1 >> 2;
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
enc4 = chr3 & 63;
if (isNaN(chr2)) {
enc3 = enc4 = 64;
} else if (isNaN(chr3)) {
enc4 = 64;
}
output = output + this.keyStr.charAt(enc1) + this.keyStr.charAt(enc2) + this.keyStr.charAt(enc3) + this.keyStr.charAt(enc4);
} while (i < input.length);
return output;
}
但是在 IE 中,我收到以下错误:
chr1 = input.charCodeAt(i++);
"Object doesn't supported by this property or method".
你能帮我解决这个问题吗? charCodeAt 函数似乎不起作用。
感谢您的宝贵时间。
最佳答案
关于javascript - IE 不支持 charCodeAt?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4222206/