--- title: decodeURIComponent() slug: Web/JavaScript/Reference/Global_Objects/decodeURIComponent tags: - JavaScript - URI - 统一资源标识符 - 解码 translation_of: Web/JavaScript/Reference/Global_Objects/decodeURIComponent ---
decodeURIComponent()
方法用于解码由 {{jsxref("encodeURIComponent")}} 方法或者其它类似方法编码的部分统一资源标识符(URI)。
decodeURIComponent(encodedURI)
encodedURI
一个解码后的统一资源标识符(URI)字符串,处理前的URI经过了给定格式的编码。
当该方法使用不当时,将会抛出一个{{jsxref("URIError")}}(“格式错误的URI序列”)异常。
将已编码 URI 中所有能识别的转义序列转换成原字符。
decodeURIComponent("JavaScript_%D1%88%D0%B5%D0%BB%D0%BB%D1%8B"); // "JavaScript_шеллы"
try { var a = decodeURIComponent('%E0%A4%A'); } catch(e) { console.error(e); } // URIError: malformed URI sequence