Several methods of JavaScript coding in detail _ basics

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.