js中base64编码以下两个函数实现
btoa() // 编码 atob() // 解码
但是以上函数只对 ASCII 字符有效,对于非ASCII 字符,比如中文字符,必须通过转换
function b64Encode(str) { return btoa(encodeURIComponent(str)); } function b64Decode(str) { return decodeURIComponent(atob(str)); } b64Decode(b64Encode('中国'))
Leave a Reply