JavaScript escape() 函數(shù)

定義和用法
escape() 函數(shù)可對字符串進(jìn)行編碼,這樣就可以在所有的計算機(jī)上讀取該字符串。
該方法不會對 ASCII 字母和數(shù)字進(jìn)行編碼,也不會對下面這些 ASCII 標(biāo)點符號進(jìn)行編碼: * @ - _ + . / 。其他所有的字符都會被轉(zhuǎn)義序列替換。
提示: 使用 unescape() 方法對字符串進(jìn)行解碼。
語法
escape(string)
參數(shù) | 描述 |
---|---|
string | 必需。要被轉(zhuǎn)義或編碼的字符串。 |
瀏覽器支持
所有主要瀏覽器都支持 escape() 函數(shù)
提示和注釋
注意: escape()函數(shù)不能用于編碼 URIs(通用資源標(biāo)識符(UniformResourceIdentifier,簡稱"URI")). 可以使用函數(shù) encodeURI() 取代。
實例
實例
使用 escape() 來編碼字符串:
<script>
document.write(escape("Need tips? Visit W3Cschool!"));
</script>
document.write(escape("Need tips? Visit W3Cschool!"));
</script>
以上實例輸出結(jié)果:
Need%20tips%3F%20Visit%20W3Cschool%21
嘗試一下 ?

更多建議: