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()
ASCII codes corresponding to common characters
a-z 97-122 A-Z 65-90 0-9 45-57
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!