function charCodeAtTest(n)
{
    var str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    var s;
    s = str.charCodeAt(n - 1);
    alert("字符串第 "+ n +" 个字符的 Unicode 编码 = "+ s);
    // 返回 Unicode 字符编码。
}
alert(charCodeAtTest(1));

解决方案 »

  1.   

    charCodeAt Method
    Returns an integer representing the Unicode encoding of the character at the specified location.strObj.charCodeAt(index)Arguments
    strObjRequired. Any String object or literal.indexRequired. Zero-based index of the desired character. Valid values are between 0 and the length of the string minus 1. Res
    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. Example
    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.
    }
      

  2.   

    那如何从 Unicode 编码得到字符呢?
      

  3.   

    <script>
    alert(String.fromCharCode(11234));
    </script>
      

  4.   

    String.fromCharCode(109, 101, 105, 122, 122);  //"meizz"