如何返回表示字符的Unicode值的数字?
的charCodeAt() 方法返回一个数字,指示给定索引处的字符的Unicode值。Unicode代码点的范围是0到1,114,111。前128个Unicode代码点是ASCII字符编码的直接匹配项。
charCodeAt(index)支持以下参数-
index- 小于字符串长度的0到1之间的整数;如果未指定,则默认为0。
示例
您可以尝试运行以下代码以返回一个数字,该数字指示字符的Unicode值-
<html>
<head>
<title>JavaScript String charCodeAt() Method</title>
</head>
<body>
<script>
var str = new String( "This is string" );
document.write("str.charCodeAt(0) is:" + str.charCodeAt(0));
document.write("<br />str.charCodeAt(1) is:" + str.charCodeAt(1));
document.write("<br />str.charCodeAt(2) is:" + str.charCodeAt(2));
document.write("<br />str.charCodeAt(3) is:" + str.charCodeAt(3));
document.write("<br />str.charCodeAt(4) is:" + str.charCodeAt(4));
document.write("<br />str.charCodeAt(5) is:" + str.charCodeAt(5));
</script>
</body>
</html>热门推荐
5 短祝福语简短暖心
10 结婚祝福语粤语大全简短
11 晚上祝福语女生文案简短
12 法语妈妈生日祝福语简短
13 药厂开工祝福语大全简短
14 蛋糕节日祝福语简短英文
15 跨年的生日祝福语简短
16 文案祝福语英文短句简短
17 在家聚餐婚礼祝福语简短
18 学生节祝福语大全简短