<script type="text/javascript"> //escape()不能直接用於URL編碼,它的真正作用是返回一個字符的Unicode編碼值。比如"春節"的返回結果是%u6625%u8282,escape()不對"+"編碼 主要用於漢字編碼。 alert(escape("春節")); alert(unescape(escape("春節"))); //encodeURI()是用來對URL編碼的函數。 編碼整個url地址,但對特殊含義的符號"; / ? : @ & = + $ , #"不進行編碼。對應的解碼函數是:decodeURI()。 alert(encodeURI('http://baidu.com?hello=您好&word=文檔')); alert(decodeURI(encodeURI('http://baidu.com?hello=您好&word=文檔'))); //encodeURIComponent() 能編碼"; / ? : @ & = + $ , #"這些特殊字符。對應的解碼函數是decodeURIComponent()。 alert(encodeURIComponent('http://baidu.com?hello=您好&word=文檔')); alert(decodeURIComponent(encodeURIComponent('http://baidu.com?hello=您好&word=文檔'))); </script>