The encoding and decoding js

A, encodeURI () Definition and Usage

the encodeURI () function as a URI string is encoded.

grammar

encodeURI(URIstring)

parameter description
URIstring essential. A string containing the URI or other text to be coded.

return value

URIstring copy of which some of the characters will be replaced hexadecimal escape sequences.

Explanation

This method will not encode ASCII letters and numbers, nor will these ASCII punctuation Code: - _ ~ * '().!.

The purpose of this method is to complete URI encoding, so it has special meaning ASCII punctuation, encodeURI () function will not escape in the URI of the following:; /: @ & = + $, #?

Tips and Notes

Tip: ? If the URI contained in the separator assembly, and # such, you should use the encodeURIComponent () method of each component are encoded.

This decoding method is decodeURI ()

Two, escape () Definition and Usage

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

grammar

escape(string)
parameter description
string essential. To be escaped or encoded string.

return value

A copy of the encoded string. Some of these characters are replaced with hexadecimal escape sequences.

Explanation

This method will not encode ASCII letters and numbers, nor will following these ASCII punctuation Code: - _ ~ * '().!. All other characters will be replaced with escape sequences.

Tips and Notes

Note: You can use unescape () to escape () decodes the encoded string.

Notes: ECMAScript v3 against the use of this method, the application uses decodeURI () and decodeURIComponent () instead.

 Three, JavaScript encodeURIComponent () Definition and Usage

encodeURIComponent() 函数可把字符串作为 URI 组件进行编码。

语法

encodeURIComponent(URIstring)
参数 描述
URIstring 必需。一个字符串,含有 URI 组件或其他要编码的文本。

返回值

URIstring 的副本,其中的某些字符将被十六进制的转义序列进行替换。

说明

该方法不会对 ASCII 字母和数字进行编码,也不会对这些 ASCII 标点符号进行编码: - _ . ! ~ * ' ( ) 。

其他字符(比如 :;/?:@&=+$,# 这些用于分隔 URI 组件的标点符号),都是由一个或多个十六进制的转义序列替换的。

提示和注释

提示:请注意 encodeURIComponent() 函数 与 encodeURI() 函数的区别之处,前者假定它的参数是 URI 的一部分(比如协议、主机名、路径或查询字符串)。因此 encodeURIComponent() 函数将转义用于分隔 URI 各个部分的标点符号。
此方法解码方式decodeURIComponent

转载于:https://www.cnblogs.com/c-y-across-I/p/3172089.html

Guess you like

Origin blog.csdn.net/weixin_33795093/article/details/94107955