Home > Web Front-end > JS Tutorial > body text

JavaScript中出现乱码的处理心得_javascript技巧

WBOY
Release: 2016-05-16 18:38:21
Original
1211 people have browsed it
常见乱码情况:
1.客户端提交数据到后台,参数值有乱码情况,如:a.aspx?value="中文值"&type="%$#((&_特殊符号";
2.后台读数据到客户端后出现乱码;
3.部分文件间js引用或css样式无效。

总结解决方法:
  一:首先保证项目相关的文件格式编码(即另存为格式)统一为utf-8,特别是相关的CSS,JS文件的格式强烈建议统一为 utf-8;

  二: JS中涉及到参数提交,传递,有可能出现中文、‘_'下划线、特殊符号的地方,用escape()编码后再传递;

  三:如果数据库中之前已经存入不同编码的数据,在相关展示数据的页面后台将Request、Response的ContentEncoding属性编码设置为"utf-8"

如此,乱码不会再现了。

其它网友回复:
用Google Clsure Compiler编译一下,可以将中文转成unicode的表达形式,用什么编码就无所谓了.
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!