English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
所有分類

請問我要如何使用Javascript 把\"a\"轉換成ASCII碼為\"97\"呢?

我找了許多資料只有看到用escape()把字串轉換成ASCII
但卻不支援英文字母和數字

請求高手幫忙

感謝!

2006-04-11 11:46:25 · 2 個解答 · 發問者 ? 2 in 電腦與網際網路 程式設計

2 個解答

沒有 ASCII 轉換函數,但是有 Uni-code 的,也可以適用

charCodeAt :Returns an integer representing the Unicode encoding of the character at the specified location.

語法 : strObj.charCodeAt(index)
strObj : Required. Any String object or literal.
index : Required. Zero-based index of the desired character. Valid values are between 0 and the length of the string minus 1.

附註 : The first character in a string is at index 0, the second is at index 1, and so forth. If there is no character at the specified index, NaN is returned.

範例 : The following example illustrates the use of the charCodeAt method.

function charCodeAtTest(n){
var str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; //Initialize variable.
var n; //Declare variable.
n = str.charCodeAt(n - 1); //Get the Unicode value of the
// character at position n.
return(n); //Return the value.
}

2006-04-20 15:36:37 補充:
U r right ! the var n should be declared as an another name. But the function usage is correct.

2006-04-11 12:24:46 · answer #1 · answered by ? 2 · 0 0

傳進來的參數是 n 變數也是 n, 不會打架嗎?

2006-04-11 13:15:09 · answer #2 · answered by 卜維丰 5 · 0 0

fedest.com, questions and answers