--- title: escape() slug: Web/JavaScript/Reference/Global_Objects/escape translation_of: Web/JavaScript/Reference/Global_Objects/escape ---
废弃的 escape()
方法生成新的由十六进制转义序列替换的字符串. 使用 {{jsxref("Global_Objects/encodeURI", "encodeURI")}} 或 {{jsxref("Global_Objects/encodeURIComponent", "encodeURIComponent")}} 代替.
escape(str)
str
escape
函数是全局对象的属性. 特色字符如: @*_+-./ 被排除在外.
字符的16进制格式值,当该值小于等于0xFF时,用一个2位转移序列: %xx 表示. 大于的话则使用4位序列:%uxxxx 表示.
escape("abc123"); // "abc123" escape("äöü"); // "%E4%F6%FC" escape("ć"); // "%u0107" // special characters escape("@*_+-./"); // "@*_+-./"
Specification | Status | Comment |
---|---|---|
ECMAScript 1st Edition. | Standard | Initial definition. |
{{SpecName('ES5.1', '#sec-B.2.1', 'escape')}} | {{Spec2('ES5.1')}} | Defined in the (informative) Compatibility Annex B |
{{SpecName('ES6', '#sec-escape-string', 'escape')}} | {{Spec2('ES6')}} | Defined in the (normative) Annex B for Additional ECMAScript Features for Web Browsers |
{{ CompatibilityTable() }}
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | {{ CompatVersionUnknown() }} | {{ CompatVersionUnknown() }} | {{ CompatVersionUnknown() }} | {{ CompatVersionUnknown() }} | {{ CompatVersionUnknown() }} |
Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | {{ CompatVersionUnknown() }} | {{ CompatVersionUnknown() }} | {{ CompatVersionUnknown() }} | {{ CompatVersionUnknown() }} | {{ CompatVersionUnknown() }} | {{ CompatVersionUnknown() }} |