2009-10-09 46 views
5

我在JavaScript調試面板試圖調用使用String.charCodeAt(「9」)在Safari 3String.charCodeAt undefined?

TypeError: Result of expression 'String.charCodeAt' [undefined] is not a function.

當我嘗試做stringInstance.charCodeAt(「9」),而不是當得到這個錯誤,我拿到NaN。難道我做錯了什麼?我只想獲得一些字符的字符代碼來與按鍵進行匹配。在Firefox上,String.charCodeAt('9')返回57(按預期)。

回答

3

我認爲正確的方法是:

「9」 .charCodeAt(0)

或stringInstace.charCodeAt(的charIndex)其中的charIndex是一個整數

+1

可以請你告訴我詳細你的回答和問題我沒有找到任何區別? –

+0

'_string_.charCodeAt(_index_)'將索引作爲其參數,並使用給定的_index_查找_string_中字符的Unicode UTF-16代碼點。參數是要查找的字符串中的字符的索引,而不是字符本身。 – Suncat2000