escape definition and usage
The escape () function encodes the string so that it can be read on all computers.
| Parameters |
Description |
| String |
Necessary. The string to be escaped or encoded. |
return value
A copy of the encoded string . Some of these characters are replaced with the 16-in escape sequence.
Description
The method does not encode ASCII letters and numbers, and does not encode the following ASCII punctuation: * @-_ +. / 。 All other characters will be replaced by escape sequences.
Tips and Comments
Tip: You can use Unescape () to decode an escape () encoded string.
Note: ECMAScript v3 against using this method, the application uses decodeURI () and decodeuricomponent () to replace it.
Example:
encodeURI Definitions and usage
The encodeURI () function encodes a string as a URI.
Syntax encodeURI (
uristring)
| Parameters |
Description |
| Uristring |
Necessary. A string that contains the URI or other text to encode. |
return value
A copy of the uristring in which some of the characters will be replaced by the hexadecimal escape sequence.
Description
The method does not encode ASCII letters and numbers, and does not encode these ASCII punctuation marks:-_. ! ~ * ' ().
The purpose of this method is to encode the URI completely, so that the encodeURI () function is not escaped for the following ASCII punctuation that has special meaning in the URI:;/?:@&=+$,#
Tips and Comments
Can be decoded with decodeURI ()
Tip: If the URI component contains delimiters, for example? and #, you should encode each component separately using the encodeURIComponent () method.
Example
Definitions and Usage
The encodeURIComponent () function encodes a string as a URI component.
Grammar
encodeURIComponent (uristring)
| Parameters |
Description |
| Uristring |
Necessary. A string that contains the URI component or other text to encode. |
return value
A copy of the uristring in which some of the characters will be replaced by the hexadecimal escape sequence.
Description
The method does not encode ASCII letters and numbers, and does not encode these ASCII punctuation marks:-_. ! ~ * ' ().
Other characters (such as:;/?:@&=+$,# the punctuation marks used to separate the URI components) are replaced by one or more hexadecimal escape sequences.
Tips and Comments
tip : Note the difference between the encodeURIComponent () function and the encodeURI () function, which assumes that its arguments are part of the URI (such as protocol, host name, path, or query string). Therefore, the encodeURIComponent () function escapes the punctuation marks used to separate parts of the URI.
Example