blob: f629d4ec9bd65b2a79717190ca26bf43a17d1c83 (
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
105
106
107
108
109
110
111
112
113
114
115
116
|
---
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>
<div class="hidden">
<p>The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> and send us a pull request.</p>
</div>
<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>
<p>
<audio class="hidden"></audio>
</p>
<p>
<audio class="hidden"></audio>
</p>
|