源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

JavaSacript中charCodeAt()方法的使用详解

  • 时间:2021-08-28 22:20 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:JavaSacript中charCodeAt()方法的使用详解
 该方法返回一个数字,表示给定索引处的字符的Unicode值。 Unicode码点范围为0到1114111。前128个Unicode码点的ASCII字符编码的直接匹配。charCodeAt()将始终返回一个值小于65,536。 [b]语法[/b]
string.charCodeAt(index);

下面是参数的详细信息: [list] [*]    index: 0和1之间小于字符串的长度的整数; 如果未指定,默认为0。[/*] [/list] [b]返回值:[/b] 返回一个数字,表示给定索引处的字符的Unicode值。如果给定的索引不是0和1之间的长度,返回NaN。 [b]例子:[/b]
<html>
<head>
<title>JavaScript String charCodeAt() Method</title>
</head>
<body>
<script type="text/javascript">
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>

这将产生以下结果:
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 

  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部