JavaScript escape() 函數

定義和用法
escape() 函數可對字串進行編碼,這樣就可以在所有的電腦上讀取該字串。
該方法不會對 ASCII 字母和數字進行編碼,也不會對下麵這些 ASCII 標點符號進行編碼: * @ - _ + . / 。其他所有的字元都會被轉義序列替換。
提示: 使用 unescape() 方法對字串進行解碼。
語法
escape(string)
參數 | 描述 |
---|---|
string | 必需。要被轉義或編碼的字串。 |
流覽器支持
所有主要流覽器都支持 escape() 函數
提示和注釋
注意: escape()函數不能用於編碼 URIs(通用資源識別字(UniformResourceIdentifier,簡稱"URI")). 可以使用函數 encodeURI() 取代。
實例
實例
使用 escape() 來編碼字串:
<script>
document.write(escape("Need tips? Visit zaixian!"));
</script>
document.write(escape("Need tips? Visit zaixian!"));
</script>
以上實例輸出結果:
Need%20tips%3F%20Visit%zaixian%21
