JavaScript decodeURIComponent() 函数

定义和用法

decodeURIComponent() 函数可对 encodeURIComponent() 函数编码的 URI 进行解码。

提示:使用 encodeURIComponent() 方法可以对 URI 进行编码。

语法

decodeURIComponent(uri)
参数描述
uri必需。一个字符串,含有编码 URI 组件或其他要解码的文本。

浏览器支持

所有主要浏览器都支持 decodeURIComponent() 函数


实例

使用 decodeURIComponent() 对编码后的 URI 进行解码:

var uri="http://runoops.com/my test.php?name=ståle&car=saab";
var uri_encode=encodeURIComponent(uri);
document.write(uri_encode);
document.write("<br>");
document.write(decodeURIComponent(uri_encode));

以上实例输出结果:

http%3A%2F%2Frunoops.com%2Fmy%20test.php%3Fname%3Dst%C3%A5le%26car%3Dsaab
http://runoops.com/my test.php?name=ståle&car=saab