javascript中escape、encodeURI和encodeURIComponent

來源:互聯網
上載者:User
方法 不被編碼的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 />");

運行代碼

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.