unescape()
Deprecated: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.
注意:
unescape()
是浏览器实现的非标准功能,只是为了跨引擎兼容性而标准化。它不需要由所有 JavaScript 引擎实现,并且可能无法在所有地方工作。如果可能,请使用decodeURIComponent()
或decodeURI()
。¥Note:
unescape()
is a non-standard function implemented by browsers and was only standardized for cross-engine compatibility. It is not required to be implemented by all JavaScript engines and may not work everywhere. UsedecodeURIComponent()
ordecodeURI()
if possible.
unescape()
函数计算一个新字符串,其中十六进制转义序列被替换为它们所代表的字符。转义序列可能由 escape()
这样的函数引入。
¥The unescape()
function computes a new string in which hexadecimal escape sequences are replaced with the characters that they represent. The escape sequences might be introduced by a function like escape()
.
语法
参数
返回值
描述
¥Description
unescape()
是全局对象的函数属性。
¥unescape()
is a function property of the global object.
unescape()
函数将任何转义序列替换为其代表的字符。具体来说,它将 %XX
或 %uXXXX
(其中 X
代表一个十六进制数字)形式的任何转义序列替换为具有十六进制值 XX
/XXXX
的字符。如果转义序列不是有效的转义序列(例如,如果 %
后跟一个或没有十六进制数字),则按原样保留。
¥The unescape()
function replaces any escape sequence with the character that it represents. Specifically, it replaces any escape sequence of the form %XX
or %uXXXX
(where X
represents one hexadecimal digit) with the character that has the hexadecimal value XX
/XXXX
. If the escape sequence is not a valid escape sequence (for example, if %
is followed by one or no hex digit), it is left as-is.
注意:该函数主要用于 URL 编码,部分基于 RFC 1738 中的转义格式。
unescape()
函数不会计算字符串文字中的 转义序列。你可以将\xXX
替换为%XX
,将\uXXXX
替换为%uXXXX
,以获得unescape()
可以处理的字符串。¥Note: This function was used mostly for URL encoding and is partly based on the escape format in RFC 1738. The
unescape()
function does not evaluate escape sequences in string literals. You can replace\xXX
with%XX
and\uXXXX
with%uXXXX
to get a string that can be handled byunescape()
.
示例
使用 unescape()
规范
Specification |
---|
ECMAScript Language Specification # sec-unescape-string |
浏览器兼容性
BCD tables only load in the browser