当前位置: 首页 > 图文教程 > 网络编程 > Javascript > js字符编码函数区别分析

Javascript
Add a Table to a Word Document
Add Formatted Text to a Word Document
用jscript实现新建word文档
用jscript实现新建和保存一个word文档
Open and Print a Word Document
Use Word to Search for Files
Convert Seconds To Hours
Sample script that deletes a SQL Server database
Sample script that displays all of the users in a given SQL Server DB
firefox中用javascript实现鼠标位置的定位
div+css实现鼠标放上去,背景跟图片都会变化。
Locate a File Using a File Open Dialog Box
Save a File Using a File Save Dialog Box
用jscript实现列出安装的软件列表
List the Stored Procedures in a SQL Server database
Display SQL Server Login Mode
Display SQL Server Version Information
List all the Databases on a SQL Server
用jscript启动sqlserver
Stop SQL Server

Javascript 中的 js字符编码函数区别分析


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 242 ::
收藏到网摘: n/a

js对文字编码有3个函数: escape,encodeURI,encodeURIComponent, 对应的解码函数:unescape,decodeURI,decodeURIComponent 1、escape对ansi码0-255以外的字符进行编码输出%u****格式即unicode值,escape 方法返回一个包含了 charstring 内容的字符串值( Unicode 格式)。所有空格、标点、重音符号以及其他非 ASCII 字符都用 %xx 编码代替,其中 xx 等于表示该字符的十六进制数。例如,空格返回的是 "%20"
escape不编码字符有69个:*,+,-,.,/,@,_,0-9,a-z,A-Z
2、encodeURI类似escape,用于地址栏编码
encodeURI不编码字符有82个:!,#,$,&,',(,),*,+,,,-,.,/,:,;,=,?,@,_,~,0-9,a-z,A-Z
3、encodeURIComponent用于地址栏编码。将文本字符串编码为一个统一资源标识符 (URI) 的一个有效组件。它是将中文、韩文等特殊字符转换成utf-8格式的url编码,如果你的页面编码是gb2312的话,服务器端接收的将是乱码.
encodeURIComponent不编码字符有71个:!, ',(,),*,-,.,_,~,0-9,a-z,A-Z
所以js使用数据时可以使用escape,对于地址栏数据,最好用encodeURIComponent进行编码。