js 字符ascii碼轉換函數

字符轉ascii碼:用charCodeAt();
ascii碼磚字符:用fromCharCode();
 
看一個小例子
<script>
str="A";
code = str.charCodeAt(); 
str2 = String.fromCharCode(code);
str3 = String.fromCharCode(0x60+26);

document.write(code+'<br />');
document.write(str2+'<br />');
document.write(str3);
</script>

輸出:
65
A
z

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章