相关函数
转为url格式 | 转为汉字 |
---|---|
escape(key) | unescape(key) |
encodeURI(key) | decodeURI(key) |
encodeURIComponent(key) | decodeURIComponent(key) |
介绍
最多使用的应为encodeURIComponent
,它是将中文、韩文等特殊字符转换成utf-8格式的url编码,所以如果给后台传递参数需要使用encodeURIComponent时需要后台解码对utf-8支持(form中的编码方式和当前页面编码方式相同)。
escape不编码字符有69个:*,+,-,.,/,@,_,0-9,a-z,A-Z。
encodeURI不编码字符有82个:!,#,$,&,',(,),*,+,,,-,.,/,:,;,=,?,@,_,~,0-9,a-z,A-Z。
encodeURIComponent不编码字符有71个:!, ',(,),*,-,.,_,~,0-9,a-z,A-Z。