aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/javascript/reference/global_objects/decodeuricomponent/index.html
blob: 7857abb5753353740377077b7e83bd875cf89cb3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
---
title: decodeURIComponent()
slug: Web/JavaScript/Reference/Global_Objects/decodeURIComponent
tags:
  - JavaScript
  - URI
  - 统一资源标识符
  - 解码
translation_of: Web/JavaScript/Reference/Global_Objects/decodeURIComponent
---
<div>{{jsSidebar("Objects")}}</div>

<p><code><strong>decodeURIComponent()</strong></code> 方法用于解码由 {{jsxref("encodeURIComponent")}} 方法或者其它类似方法编码的部分统一资源标识符(URI)。</p>

<h2 id="语法">语法</h2>

<pre class="syntaxbox"><code>decodeURIComponent(<em>encodedURI</em>)</code></pre>

<h3 id="参数">参数</h3>

<dl>
 <dt><code>encodedURI</code></dt>
 <dd>编码后的部分 URI</dd>
</dl>

<h3 id="返回值">返回值</h3>

<p>一个解码后的统一资源标识符(URI)字符串,处理前的URI经过了给定格式的编码。</p>

<h3 id="异常">异常</h3>

<p>当该方法使用不当时,将会抛出一个{{jsxref("URIError")}}(“格式错误的URI序列”)异常。</p>

<h2 id="描述">描述</h2>

<p>将已编码 URI 中所有能识别的转义序列转换成原字符。</p>

<h2 id="示例">示例</h2>

<h3 id="解码一个西里尔字母的URL">解码一个西里尔字母的URL</h3>

<pre class="brush: js">decodeURIComponent("JavaScript_%D1%88%D0%B5%D0%BB%D0%BB%D1%8B");
// "JavaScript_шеллы"
</pre>

<h3 id="捕捉异常">捕捉异常</h3>

<pre class="brush: js">try {
  var a = decodeURIComponent('%E0%A4%A');
} catch(e) {
  console.error(e);
}

// URIError: malformed URI sequence</pre>

<h2 id="规范">规范</h2>

{{Specifications}}

<h2 id="浏览器兼容性">浏览器兼容性</h2>

{{Compat}}

<h2 id="相关链接">相关链接</h2>

<ul>
 <li>{{jsxref("decodeURI")}}</li>
 <li>{{jsxref("encodeURI")}}</li>
 <li>{{jsxref("encodeURIComponent")}}</li>
</ul>