以下方案仅é™?于æµ?览器环境ï¼?
æµ?览器内置的方法
��:
å?¦:
然å?Ž base64 自然就有了:
兼容情况如下:
当然,ä¾?然存在å?¯能失败的情况。
具体请å?‚考
æµ?览器内置的方法
atob, btoa 仅能处ç?† utf-8 编ç ?的 ascii 字符,ä¸?能直接作用于 Unicode 字符串,所以需è¦?æ?ž定 utf-8 编ç ?,解ç ?:
// utf-8 encode, decode
function encode_utf8(s) {
return unescape(encodeURIComponent(s));
}
function decode_utf8(s) {
return decodeURIComponent(escape(s));
}
��:
å?¦:
然å?Ž base64 自然就有了:
// base64, encode, decode
function base64Encode(str) {
return btoa(unescape(encodeURIComponent(str)));
}
function base64Decode(str) {
return decodeURIComponent(escape(atob(str)));
}
// utf-8 encode, decode
function encode_utf8(s) {
return unescape(encodeURIComponent(s));
}
function decode_utf8(s) {
return decodeURIComponent(escape(s));
}
兼容情况如下:
- Win32
- Firefox 1.5.0.6
Firefox 1.5.0.4Internet Explorer 6.0.2900.2180- Opera 9.0.8502
- MacOS
- Camino 2006061318 (1.0.2)
- Firefox 1.5.0.4
- Safari 2.0.4 (419.3)
当然,ä¾?然存在å?¯能失败的情况。
具体请å?‚考
上一篇:grunt-css-sprite
共5评论
风æµ?鬼说:
于 2015-1-28 8:57:03 #
仔细拜读,表示支æŒ?ï¼?
甲å?ˆ年(马)腊月åˆ?ä¹? 2015-1-28
回å¤?
美国æœ?务器说:
于 2015-4-23 17:47:40 #
收è—?了好文乙未年(羊)三月åˆ?五 2015-4-23
回å¤?
算沙说:
于 2015-5-8 11:15:03 #
原æ?¥你在这里
回å¤?
尚å?¾网说:
于 2015-5-14 16:53:10 #
ä¸?止一次的æ?¥访,一如既往的支æŒ?。
回å¤?
fengliugui说:
于 2015-5-16 10:24:57 #
pretty good blog,come again next time。
回å¤?