当前位置: 首页 > 图文教程 > 网络编程 > Javascript > JavaScript中出现乱码的处理心得

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 中的 JavaScript中出现乱码的处理心得


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2010-01-10   浏览: 354 ::
收藏到网摘: n/a

最近项目中遇到些字符串乱码问题,解决后有些心得,记录于此。 常见乱码情况:
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的表达形式,用什么编码就无所谓了.