Home  >  Article  >  Web Front-end  >  Difference analysis of js character encoding functions_javascript skills

Difference analysis of js character encoding functions_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:58:001409browse

1. escape encodes characters other than ansi code 0-255 and outputs them in %u**** format, which is a unicode value. The escape method returns a string value (Unicode format) containing the content of charstring. All spaces, punctuation, accents, and other non-ASCII characters are replaced with the %xx encoding, where xx is equal to the hexadecimal number representing the character. For example, the space returned is " "
There are 69 unencoded characters in escape: *, , -, ., /, @, _, 0-9, a-z, A-Z

2. encodeURI is similar to escape , used for address bar encoding
encodeURI does not encode 82 characters: !, #, $, &, ', (,), *, ,,,-,.,/,:,;,=,?, @, _, ~, 0-9, a-z, A-Z

3. encodeURIComponent is used for address bar encoding. Encodes a text string into a valid component of a Uniform Resource Identifier (URI). It converts special characters such as Chinese and Korean into url encoding in UTF-8 format. If your page encoding is gb2312, the server will receive garbled characters.
encodeURIComponent has 71 unencoded characters:!, ' ,(,),*,-,.,_,~,0-9,a-z,A-Z

So js can use escape when using data. For address bar data, it is best to use encodeURIComponent for encoding.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn