Escape defines and uses the escape () function to encode a string so that the string can be read on all computers. The description string of the syntax escape (string) parameter is required. The string to be escaped or encoded. Returns a copy of The encoded string. Some characters are replaced with hexadecimal escape sequences. For more information, see
Escape definition and usage
The escape () function can encode a string so that the string can be read on all computers.
Parameters |
Description |
String |
Required. The string to be escaped or encoded. |
Return Value
EncodedString. Some characters are replaced with hexadecimal escape sequences.
Description
This method does not encode ASCII letters and numbers or the following ASCII punctuation characters: * @-_ + ./. All other characters are replaced by escape sequences.
Tips and comments
Tip: You can use unescape () to decode the escape () encoded string.
Note: ECMAScript v3 rejects this method. The application uses decodeURI () and decodeURIComponent () to replace it.
Example:
EncodeURI definition and usage
The encodeURI () function can encode a string as a URI.
Syntax encodeURI (
URIstring)
Parameters |
Description |
URIstring |
Required. A string containing URI or other text to be encoded. |
Return Value
A copy of URIstring, some of which will be replaced by the hexadecimal escape sequence.
Description
This method does not encode ASCII letters and numbers, and does not encode these ASCII punctuation marks :-_.! ~ *'().
The purpose of this method is to fully encode the URI. Therefore, the encodeURI () function will not escape the following ASCII punctuation marks with special meanings in the URI :;/? : @ & =+ $ ,#
Tips and comments
You can use decodeURI () for decoding.
Tip: If the URI component contains a separator, such? And #, use the encodeURIComponent () method to encode each component.
Example
Definition and usage
The encodeURIComponent () function can encode a string as a URI component.
Syntax
encodeURIComponent(URIstring)
Parameters |
Description |
URIstring |
Required. A string containing the URI component or other text to be encoded. |
Return Value
A copy of URIstring, some of which will be replaced by the hexadecimal escape sequence.
Description
This method does not encode ASCII letters and numbers, and does not encode these ASCII punctuation marks :-_.! ~ *'().
Other characters (such :;/? : @ & =+ $, # The punctuation marks used to separate URI components) are all replaced by one or more hexadecimal escape sequences.
Tips and comments
Prompt: Note the differences between the encodeURIComponent () function and the encodeURI () function. The former assumes that its parameters are part of the URI (such as the protocol, host name, path, or query string ). Therefore, the encodeURIComponent () function uses escape characters to separate the punctuation marks of each part of the URI.
Example