JavaScript escape()Function

函数参考手册JavaScript Global Functions

Definition and Usage

The escape() function encodes a string so that it can be read on all computers.

This method does not encode ASCII letters and digits, nor does it encode the following ASCII punctuation marks: * @ - _ + . / . All other characters are replaced by escape sequences.

Tip:Useunescape()method to decode the string.

Note:The escape() function has been removed from the Web standards, so try not to use this function; you can useencodeURIorencodeURIComponentinstead.

Syntax

escape(string)

Parameter Description
string Required. The string to be escaped or encoded.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the escape() function


Tips and Notes

Note:The escape() function cannot be used to encode URIs (Uniform Resource Identifier, "URI" for short). You can use the functionencodeURI()instead.


Examples

Examples

Use escape() to encode a string:

<script>

document.write(escape("Need tips? Visit EXAMPLE!"));

</script>

The output of the above example is:

Need%20tips%3F%20Visit%20EXAMPLE%21

Try it yourself »


函数 参考手册JavaScript Global Functions Other Extensions