escape
escape
废弃的 escape()
方法生成新的由十六进制转义序列替换的字符串. 使用encodeURI
或encodeURIComponent
代替.
语法
escape(str)
参数
str
待编码的字符串.
返回值
一个新字符串,其中某些字符已经被转义。
描述
escape
函数是全局对象的属性. 特色字符如: @*_+-./ 被排除在外.
字符的16进制格式值,当该值小于等于0xFF时,用一个2位转移序列: %xx 表示. 大于的话则使用4位序列:%u
xxxx 表示.
示例
escape('abc123' // "abc123"
escape('äöü' // "%E4%F6%FC"
escape('ć' // "%u0107"
// special characters
escape('@*_+-./' // "@*_+-./"
规范
Specification | Status | Comment |
---|---|---|
ECMAScript 1st Edition (ECMA-262) | Standard | Initial definition. |
ECMAScript 5.1 (ECMA-262)The definition of 'escape' in that specification. | Standard | Defined in the (informative) Compatibility Annex B |
ECMAScript 2015 (6th Edition, ECMA-262)The definition of 'escape' in that specification. | Standard | Defined in the (normative) Annex B for Additional ECMAScript Features for Web Browsers |
ECMAScript Latest Draft (ECMA-262)The definition of 'escape' in that specification. | Living Standard | Defined in the (normative) Annex B for Additional ECMAScript Features for Web Browsers |
浏览器兼容性
Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic support | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
Feature | Android | Chrome for Android | Edge | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|---|
Basic support | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |