decodeURI() 函数解码一个由encodeURI 先前创建的统一资源标识符(URI)或类似的例程。

语法

decodeURI(encodedURI)

参数

encodedURI
一个完整的编码过的 URI

返回值

A new string representing the unencoded version of the given encoded Uniform Resource Identifier (URI).

Exceptions

Throws an URIError ("malformed URI sequence") exception when encodedURI contains invalid character sequences.

描述

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

示例

解码一个西里尔字母(Cyrillic)URL

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_шеллы"

捕捉异常

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

// URIError: malformed URI sequence

规范

规范 状态 备注
ECMAScript 3rd Edition (ECMA-262) Standard 初始定义
ECMAScript 5.1 (ECMA-262)
decodeURI
Standard  
ECMAScript 2015 (6th Edition, ECMA-262)
decodeURI
Standard  
ECMAScript Latest Draft (ECMA-262)
decodeURI
Draft  

浏览器兼容性

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!

特性 Chrome Firefox (Gecko) Internet Explorer Opera Safari
基础功能 (Yes) (Yes) (Yes) (Yes) (Yes)
特性 Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
基础功能 (Yes) (Yes) (Yes) (Yes) (Yes) (Yes)

相关链接