JavaScript对编码字符串进行解码|unEscape() 全局函数
定义与用法
unescape() 函数可对通过 escape() 编码的字符串进行解码。
提示:
- 使用函数escape() 对字符串进行编码。
- unescape()不能对 URI(通用资源标识符:UniformResourceIdentifier,简称”URI”)进行解码. 解码 URI 请使用 decodeURI() 方法。
语法格式
unescape(string)
浏览器支持
函数 | |||||
---|---|---|---|---|---|
UnEscape() | Yes | Yes | Yes | Yes | Yes |
所有主要浏览器都支持 unescape() 函数。
参数说明
参数 | 描述 |
---|---|
string | 必需。要解码的字符串。 |
示例代码
在本例中,我们将使用 escape() 来编码字符串,然后使用 unescape() 对其解码:
var str="Need tips? Visit RUNOON!";
var str_esc=escape(str);
document.write(str_esc + "<br>");
document.write(unescape(str_esc));