Home > Web Front-end > JS Tutorial > JavaScript method to get the ASCII code corresponding to a character

JavaScript method to get the ASCII code corresponding to a character

巴扎黑
Release: 2018-05-11 15:02:30
Original
4357 people have browsed it

The following editor will bring you an example of JS obtaining the ASCII code corresponding to the character. The editor thinks it’s pretty good, and now I want to give it to you and give it as a reference. Let’s follow the editor and take a look.

Sometimes you need to use the ASCII code of a character, and you may forget the number corresponding to the character and the ASCII code during debugging.

Recently, I like to use the browser console to run JS code directly. Paste this code directly to the browser console to debug (Google Chrome shortcut key ctrl+shift+j)

function GetAsciiCode(){
var str = prompt("请输入几个字符","");//接收字符串
var strAscii = new Array();//用于接收ASCII码
for(var i = 0 ; i < str.length ; i++ ){
strAscii[i] = str.charCodeAt(i);//只能把字符串中的字符一个一个的解码
}
var getAscii = "";//把这些ASCII码按顺序排列
for(var i = 0 ; i < strAscii.length ; i++ ){
getAscii += strAscii[i];
getAscii += " ";
}
alert("这些字符的ASCII码依次是:"+getAscii);//输出结果给人看
}
GetAsciiCode()
Copy after login

ASCII codes corresponding to common characters

a-z 97-122
A-Z 65-90
0-9 45-57
Copy after login

The above is the detailed content of JavaScript method to get the ASCII code corresponding to a character. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template