常用代码与插件 - ASCII与字符互转 ¶
作者:KK
发表日期:2017.06.27
ASCII转字符 ¶
代码是String.fromCharCode(ASCII码)
console.log(String.fromCharCode(48)); //数字0
console.log(String.fromCharCode(49)); //数字1
console.log(String.fromCharCode(50)); //数字2
console.log(String.fromCharCode(65)); //字母A
console.log(String.fromCharCode(66)); //字母B
console.log(String.fromCharCode(67)); //字母C
console.log(String.fromCharCode(21)); //叹号
console.log(String.fromCharCode(23)); //#号
console.log(String.fromCharCode(10)); //换行符 \n
console.log(String.fromCharCode(13)); //回车符 \r
console.log(String.fromCharCode(9)); //制表符(Tab) \t
字符转ASCII ¶
用字符串对象的charCodeAt
方法
console.log('A'.charCodeAt()); //65
console.log('B'.charCodeAt()); //66
console.log('C'.charCodeAt()); //67
console.log('\n'.charCodeAt()); //10
console.log('\r'.charCodeAt()); //13
console.log('\t'.charCodeAt()); //9