JavaSacript中charCodeAt()方法的使用详解
该方法返回一个数字,表示给定索引处的字符的Unicode值。
Unicode码点范围为0到1114111。前128个Unicode码点的ASCII字符编码的直接匹配。charCodeAt()将始终返回一个值小于65,536。
语法
string.charCodeAt(index);
下面是参数的详细信息:
- index:0和1之间小于字符串的长度的整数;如果未指定,默认为0。
返回值:
返回一个数字,表示给定索引处的字符的Unicode值。如果给定的索引不是0和1之间的长度,返回NaN。
例子:
<html>
<head>
<title>JavaScriptStringcharCodeAt()Method</title>
</head>
<body>
<scripttype="text/javascript">
varstr=newString("Thisisstring");
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>
这将产生以下结果:
str.charCodeAt(0)is:84 str.charCodeAt(1)is:104 str.charCodeAt(2)is:105 str.charCodeAt(3)is:115 str.charCodeAt(4)is:32 str.charCodeAt(5)is:105
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下