.
3ss.cn

javascript中怎么将url转换成汉字

在javascript中,可以使用unescape()函数、decodeURIComponent()函数和decodeURI()函数将url转换成汉字。

本教程操作环境:windows7系统、javascript1.8.5版、Dell G3电脑。

相关函数

转为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

赞(0)
未经允许不得转载:互联学术 » javascript中怎么将url转换成汉字

评论 抢沙发