参考资料: 
encodeURI encodeURIComponent escape区别 
http://yunzhongxia.iteye.com/blog/1126873 
AS3中的encodeURI,encodeURIComponent,decodeURI以及decodeURIComponent 
http://bbs.9ria.com/thread-71-1-1.html 
 
 
 
 
 
把字符串转为URL编码时,会自动把其大部分的非字母数字的字符替换为%十六进制序列。 
 
 
URL常用地方--路径 
最常见的是中文路径,编码URL时,会自动转为%十六进制序列。 
而转换解码则用全局函数encodeURI和decodeURI。 
 
 
var str:String = "中文字符"; 
 
var encodeStr:String = encodeURI(str) 
var decodeStr:String = decodeURI(encodeStr); 
trace(encodeStr);//输出:%E4%B8%AD%E6%96%87%E5%AD%97%E7%AC%A6 
trace(decodeStr);//输出:中文字符 
 
var escapeStr:String = escape(str) 
var unescapeStr:String = unescape(escapeStr); 
trace(escapeStr);//输出:%u4E2D%u6587%u5B57%u7B26 
trace(unescapeStr);//输出:中文字符 
 
trace(unescape(encodeStr));//输出:????????????(乱码) 
trace(decodeURI(escapeStr));//报错:URIError: Error #1052: 传递给 decodeURI 函数的 URI 无效。  
 
以上测试用例说明,encodeURI、decodeURI 和 escape、unescape 是不可互换的,否则会乱码或报错。 
 
 
- 如果要对一个URI全部进行编码,采用encodeURI函数。
 - 如果要对URI中的参数,特别是中文参数、特殊字符进行转移,采用encodeURIComponent函数。
 - escape除了 ASCII 字母、数字和特定的符号外,对传进来的字符串全部进行转义编码,因此如果想对URL编码,最好不要使用此方法。
 
 
  
 
 |