Home  >  Article  >  Web Front-end  >  js escape,unescape解决中文乱码问题的方法_javascript技巧

js escape,unescape解决中文乱码问题的方法_javascript技巧

WBOY
WBOYOriginal
2016-05-16 18:26:141297browse
1.escape 方法

对 String 对象编码以便它们能在所有计算机上可读,
escape(charString)
必选项 charstring 参数是要编码的任意 String 对象或文字。
说明 :
  escape 方法返回一个包含了 charstring 内容的字符串值( Unicode 格式)。所有空格、标点、重音符号以 及 其他非 ASCII字符都用 %xx 编码代替,其中 xx 等于表示该字符的十六进制数。例如,空格返回的是"%20 " 。 字符值大于 255 的以 %uxxxx 格式存储。

  注意 :escape 方法不能够用来对统一资源标示码 (URI) 进行编码。对其编码应使用 encodeURI和encodeURIComponent 方法。

2.unescape 方法

解码用 escape 方法进行了编码的 String 对象。
unescape(charstring)
必选项 charstring 参数是要解码的 String 对象。
说明 :
unescape 方法返回一个包含 charstring 内容的字符串值。所有以 %xx 十六进制形式编码的字符都用 ASCII 字符集中等价的字符代替。 以 %uxxxx 格式(Unicode 字符)编码的字符用十六进制编码 xxxx 的 Unicode 字符代替.
注意 : unescape 方法不能用于解码统一资源标识码 (URI)。解该码可使用 decodeURI 和decodeURIComponent 方法。
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