decodeURIComponent()
decodeURIComponent()
函数对先前由 encodeURIComponent()
或类似例程创建的统一资源标识符 (URI) 组件进行解码。
¥The decodeURIComponent()
function decodes a Uniform Resource Identifier (URI) component previously created by encodeURIComponent()
or by a similar routine.
Try it
语法
参数
返回值
例外情况
描述
¥Description
decodeURIComponent()
是全局对象的函数属性。
¥decodeURIComponent()
is a function property of the global object.
decodeURIComponent()
使用与 decodeURI()
中描述的相同的解码算法。它解码所有转义序列,包括那些不是由 encodeURIComponent
创建的序列,例如 -.!~*'()
。
¥decodeURIComponent()
uses the same decoding algorithm as described in decodeURI()
. It decodes all escape sequences, including those that are not created by encodeURIComponent
, like -.!~*'()
.
示例
解码西里尔字母 URL 组件
捕获错误
从 URL 解码查询参数
¥Decoding query parameters from a URL
decodeURIComponent()
不能直接用于解析 URL 中的查询参数。这需要一些准备。
¥decodeURIComponent()
cannot be used directly to parse query parameters from a URL. It needs a bit of preparation.
function decodeQueryParam(p) {
return decodeURIComponent(p.replace(/\+/g, " "));
}
decodeQueryParam("search+query%20%28correct%29");
// 'search query (correct)'
规范
Specification |
---|
ECMAScript Language Specification # sec-decodeuricomponent-encodeduricomponent |
浏览器兼容性
BCD tables only load in the browser
也可以看看
¥See also