JavaScript:字符和unicode码转换

字符转unicode码:用charCodeAt();

'a1'.charCodeAt(1);    //49 (0x31)
'a1'.charCodeAt();     //97 (0x61)
'中'.charCodeAt();     //20013

unicode码转字符:用fromCharCode();

String.fromCharCode(0x61,0x31,20013); //"a1中"
posted @ 2019-01-09 17:39  xuejianbest  阅读(289)  评论(0编辑  收藏  举报