javascript实现unicode与ASCII相互转换的方法
本文实例讲述了javascript实现unicode与ASCII相互转换的方法。分享给大家供大家参考,具体如下:
<head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>Unicode、ASCII相互转换</title> <script type="text/javascript"> //AsciiToUnicode("中国"); UnicodeToAscii("测试"); //ASCII 转换 Unicode function AsciiToUnicode(content) { result = ''; for (var i=0; i<content.length; i++) result+='' + content.charCodeAt(i) + ';'; alert("ASCII:"+content+"\nUnicode:"+result); } //Unicode 转换 ASCII function UnicodeToAscii(content) { var code = content.match(/(\d+);/g); result= ''; for (var i=0; i<code.length; i++) result += String.fromCharCode(code[i].replace(/[]/g, '')); alert("Unicode:"+content+"\nASCII:"+result); } </script> </head> <body> </body> </html>
希望本文所述对大家JavaScript程序设计有所帮助。
相关推荐
86530296 2020-11-10
周游列国之仕子 2020-09-21
88540591 2020-06-16
89411051 2020-06-14
mjshldcsd 2020-06-14
88384957 2020-06-12
84590091 2020-06-08
88540591 2020-06-04
88540591 2020-06-01
81214051 2020-06-01
84590091 2020-05-03
81214051 2020-04-25
honghao0 2020-04-24
84590091 2020-04-22
85271041 2020-04-10
88384957 2020-03-27
85271041 2020-03-08