decodeURIComponent()函式

decodeURIComponent()函式

作用:可對encodeURIComponent()函式編碼的URI進行解碼

語法,返回值,實例,

語法

decodeURIComponent(URIstring)
參數
描述
URIstring
必需。一個字元串,含有編碼 URI 組件或其他要解碼的文本。

返回值

URIstring的副本,其中的十六進制轉義序列將被它們表示的字元替換。

實例

在本例中,我們將使用 decodeURIComponent() 對編碼後的 URI 進行解碼:
<script type="text/javascript">
var test1="你好,世界!"
document.write("測試一:"+encodeURIComponent(test1)+ "<br />")
var test2=encodeURIComponent(test1)
document.write("測試二:"+decodeURIComponent(test2))
</script>
輸出結果:
測試一:%E4%BD%A0%E5%A5%BD%EF%BC%8C%E4%B8%96%E7%95%8C%EF%BC%81
測試二:你好,世界!

相關詞條

熱門詞條

聯絡我們