Home > Web Front-end > JS Tutorial > js escape, unescape method to solve Chinese garbled problem_javascript skills

js escape, unescape method to solve Chinese garbled problem_javascript skills

WBOY
Release: 2016-05-16 18:26:14
Original
1374 people have browsed it
1.escape method

Encode String objects so that they are readable on all computers,
escape(charString)
The required charstring parameter is any String to be encoded Object or text.
Description:
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, spaces are returned as " ". Character values ​​greater than 255 are stored in %uxxxx format.

Note: The escape method cannot be used to encode a Uniform Resource Identifier (URI). To encode it use the encodeURI and encodeURIComponent methods.

2.unescape method

Decodes a String object encoded with the escape method.
unescape(charstring)
Required charstring parameter is the String object to be decoded.
Description:
The unescape method returns a string value containing the contents of charstring. All characters encoded in %xx hexadecimal form are replaced by equivalent characters in the ASCII character set. Characters encoded in %uxxxx format (Unicode characters) are replaced with Unicode characters with hexadecimal encoding xxxx.
Note: The unescape method cannot be used to decode Uniform Resource Identifiers (URIs). This code can be decoded using the decodeURI and decodeURIComponent methods.
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template