JavaScript:decodeURIComponent()
一、概述
decodeURIComponent() 函数可对 encodeURIComponent() 函数编码的 URI 进行解码。
提示:使用 encodeURIComponent() 方法可以对 URI 进行编码。
语法:decodeURIComponent(uri)
参数
uri:字符串,含有编码 URI 组件或其他要解码的文本。
二、实例
使用 decodeURIComponent() 对编码后的 URI 进行解码:
var uri="https://www.runoob.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));
输出结果:
https%3A%2F%2Fwww.runoob.com%2Fmy%20test.php%3Fname%3Dst%C3%A5le%26car%3Dsaab
https://www.runoob.com/my test.php?name=ståle&car=saab