方法 | 不被编码的ASCII字符 | ||
---|---|---|---|
相同字符 | 不同字符 | 总计 | |
escape() | 0-9 a-z A-Z * . _ - |
@ + / | 69 |
encodeURI() | ! ( ) ' ~ , : ; # $ @ / & ? + = | 82 | |
encodeURIComponent() | ! ( ) ' ~ | 71 |
字符 | ASCII (十六进制) |
Unicode (十六进制) |
Unicode (二进制) |
UTF-8存储 (十六进制) |
UTF-8字节流 (二进制) |
escape | encodeURI | encodeURIComponent |
---|---|---|---|---|---|---|---|---|
A | 41 | 41 | 00000000 01000001 | 41 | 01000001 | A | A | A |
Z | 5A | 5A | 00000000 01011010 | 5A | 01011010 | Z | Z | Z |
a | 61 | 61 | 00000000 01100001 | 61 | 01100001 | a | a | a |
z | 7A | 7A | 00000000 01111010 | 7A | 01111010 | z | z | z |
0 | 30 | 30 | 00000000 00110000 | 30 | 00110000 | 0 | 0 | 0 |
9 | 39 | 39 | 00000000 00111001 | 39 | 00111001 | 9 | 9 | 9 |
一 | - | 4E 00 | 01001110 00000000 | E4 B8 80 | 11100100 10111000 10000000 | %u4E00 | %E4%B8%80 | %E4%B8%80 |
龥 | - | 9F A5 | 10011111 10100101 | E9 BE A5 | 11101001 10111110 10100101 | %u9FA5 | %E9%BE%A5 | %E9%BE%A5 |
欢乐在不言之中!
测试代码:
var s = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789*._-"; document.writeln("<br />测试1. 不被编码的字符 —— ASCII字母和数字和 * . _ -"); document.writeln("<hr />"); document.writeln("escape(\"" + s + "\") : " + escape(s) + "<br />"); document.writeln("encodeURI(\"" + s + "\") : " + encodeURI(s) + "<br />"); document.writeln("encodeURIComponent(\"" + s + "\") : " + encodeURIComponent(s) + "<br />"); document.writeln("<br />测试2. 不被编码的字符 —— 特殊符号"); document.writeln("<hr />"); document.writeln("escape(\"*-+@_./\") : " + escape("*@-_+./" ) + "<br />"); document.writeln("encodeURI(\"!*()'~_.,:;#$@/&?+-=\") : " + encodeURI("!*()'~-_.,:;#$@/&?+=" ) + "<br />"); document.writeln("encodeURIComponent(\"!*()'~-_.\") : " + encodeURIComponent("!*()'~-_." ) + "<br />"); document.writeln("<br />测试3. 会被编码的字符 —— 特殊符号"); document.writeln("<hr />"); document.writeln("escape(\"?!=()#%&$,:;'[]{}\\`\") : " + escape("?!=()#%&$,:;'[]{}\\`") + "<br />"); document.writeln("encodeURI(\"[]{}\\\"%`\") : " + encodeURI("[]{}\\\"%`" ) + "<br />"); document.writeln("encodeURIComponent(\",:;#$@/&?+=[]{}\\\"%`\") : " + encodeURIComponent(",:;#$@/&?+=[]{}\\\"%`" ) + "<br />"); document.writeln("escape(\"然\") : " + escape("然") + "<br />"); document.writeln("encodeURI(\"然\") : " + encodeURI("然") + "<br />"); document.writeln("encodeURIComponent(\"然\") : " + encodeURIComponent("然") + "<br />");