JavaScript decodeURIComponent() 函數(shù)
定義和用法
decodeURIComponent() 函數(shù)可對 encodeURIComponent() 函數(shù)編碼的 URI 進行解碼。
語法
decodeURIComponent(URIstring)
參數(shù) | 描述 |
---|---|
URIstring | 必需。一個字符串,含有編碼 URI 組件或其他要解碼的文本。 |
返回值
URIstring 的副本,其中的十六進制轉(zhuǎn)義序列將被它們表示的字符替換。
實例
在本例中,我們將使用 decodeURIComponent() 對編碼后的 URI 進行解碼:
<script type="text/javascript"> var test1="http://www.dbjr.com.cn/My first/" document.write(encodeURIComponent(test1)
+ "<br />") document.write(decodeURIComponent(test1)
) </script>
輸出:
http%3A%2F%2Fwww.dbjr.com.cn%2FMy%20first%2F http://www.dbjr.com.cn/My first/
TIY
- decodeURIComponent()
- 如何使用 decodeURIComponent() 對編碼后的 URI 進行解碼。