// 将字符转换为 ASCII 码
function charToAscii(char) {
return char.charCodeAt(0);
}
// 将 ASCII 码转换为字符
function asciiToChar(ascii) {
return String.fromCharCode(ascii);
}
// 示例
console.log(charToAscii('A')); // 输出: 65
console.log(asciiToChar(65)); // 输出: A
charToAscii
函数:接受一个字符作为参数,并使用 charCodeAt(0)
方法将其转换为对应的 ASCII 码。asciiToChar
函数:接受一个 ASCII 码作为参数,并使用 String.fromCharCode()
方法将其转换为对应的字符。上一篇:js 闭包
下一篇:js toast
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站