aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/javascript/reference/global_objects/decodeuri/index.html
blob: f45613cee20b328f9a7a88cf710d00a692db900e (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
---
title: decodeURI()
slug: Web/JavaScript/Reference/Global_Objects/decodeURI
tags:
  - JavaScript
  - URI
  - decodeURI()
  - 统一资源标识符
translation_of: Web/JavaScript/Reference/Global_Objects/decodeURI
---
<div>{{jsSidebar("Objects")}}</div>

<div></div>

<p><code><strong>decodeURI()</strong></code> 函数能解码由{{jsxref("encodeURI")}} 创建或其它流程得到的统一资源标识符(URI)。</p>

<p>{{EmbedInteractiveExample("pages/js/globalprops-decodeuri.html")}}</p>

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

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

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

<dl>
 <dt><code>encodedURI</code></dt>
 <dd>一个完整的编码过的 URI</dd>
</dl>

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

<p>返回一个给定编码统一资源标识符(URI)的未编码版本的新字符串。</p>

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

<p><code><em>encodedURI</em></code> 包含无效字符序列时,引发{{jsxref("URIError")}}(“格式错误的URI序列”)异常。</p>

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

<p>将已编码 URI 中所有能识别的转义序列转换成原字符,但不能解码那些不会被 {{jsxref("encodeURI")}} 编码的内容(例如 "<code>#</code>")。</p>

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

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

<pre class="brush: js">decodeURI("https://developer.mozilla.org/ru/docs/JavaScript_%D1%88%D0%B5%D0%BB%D0%BB%D1%8B");
// "https://developer.mozilla.org/ru/docs/JavaScript_шеллы"
</pre>

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

<pre>try {
  var a = decodeURI('%E0%A4%A');
} catch(e) {
  console.error(e);
}

// URIError: malformed URI sequence</pre>

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

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">规范</th>
   <th scope="col">状态</th>
   <th scope="col">备注</th>
  </tr>
  <tr>
   <td>{{SpecName('ES3')}}</td>
   <td>{{Spec2('ES3')}}</td>
   <td>初始定义</td>
  </tr>
  <tr>
   <td>{{SpecName('ES5.1', '#sec-15.1.3.1', 'decodeURI')}}</td>
   <td>{{Spec2('ES5.1')}}</td>
   <td></td>
  </tr>
  <tr>
   <td>{{SpecName('ES6', '#sec-decodeuri-encodeduri', 'decodeURI')}}</td>
   <td>{{Spec2('ES6')}}</td>
   <td></td>
  </tr>
  <tr>
   <td>{{SpecName('ESDraft', '#sec-decodeuri-encodeduri', 'decodeURI')}}</td>
   <td>{{Spec2('ESDraft')}}</td>
   <td></td>
  </tr>
 </tbody>
</table>

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

<p>{{Compat("javascript.builtins.decodeURI")}}</p>

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

<div></div>

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