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

源码网商城

简介JavaScript中charAt()方法的使用

  • 时间:2021-01-02 16:40 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:简介JavaScript中charAt()方法的使用
 这个方法返回从指定索引的字符。 字符串中的字符进行索引从左向右。第一个字符的索引是0,并且在一个叫 stringName字符串的最后一个字符的索引是stringName.length- 1。 [b]语法[/b]
string.charAt(index);

下面是参数的详细信息: [list] [*]    index: 介于0和1比串的长度以下的整数。[/*] [/list] [b]返回值:[/b] 返回从指定索引的字符。 [b]例子:[/b]
<html>
<head>
<title>JavaScript String charAt() Method</title>
</head>
<body>
<script type="text/javascript">
  var str = new String( "This is string" );
  document.writeln("str.charAt(0) is:" + str.charAt(0)); 
  document.writeln("<br />str.charAt(1) is:" + str.charAt(1)); 
  document.writeln("<br />str.charAt(2) is:" + str.charAt(2)); 
  document.writeln("<br />str.charAt(3) is:" + str.charAt(3)); 
  document.writeln("<br />str.charAt(4) is:" + str.charAt(4)); 
  document.writeln("<br />str.charAt(5) is:" + str.charAt(5)); 
</script>
</body>
</html>

这将产生以下结果:
str.charAt(0) is:T 
str.charAt(1) is:h 
str.charAt(2) is:i 
str.charAt(3) is:s 
str.charAt(4) is: 
str.charAt(5) is:i 

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

扫一扫进微信版
返回顶部