JavaScript字符串中的字符数组
源程序:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>JavaScript字符串中的字符数组</title>
</head>
<body>
<script type="text/javascript">
var str = "www.dreamdu.com";
document.write(str+"的第五个字母是"+str);
document.write("<br />");
document.write(str+" = "+str[0]+str[1]+str[2]+str[3]+str[4]+str[5]+str[6]+str[7]+str[8]+str[9]+str[10]+str[11]+str[12]+str[13]+str[14]);
</script>
</body>
</html>
输出结果:
www.dreamdu.com的第五个字母是undefined
www.dreamdu.com = undefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefined
注意:
1、JavaScript字符串中的每个值可以使用字符数组的方式访问,注意字符串数组的索引是从0开始的。可以使用charAt()函数代替数组索引方式。(IE不支持字符数组,请使用charAt函数)
相关文档:
一、前言
Ajax,异步JavaScript和XML,前面已经解释过,所以Ajax的学习还包含JavaScript和XML,这里我们先看JavaScript,而JavaScript实际上又是包含JavaScript语法和HTML DOM即文档对象模型的,接下来会分别介绍。
JavaScript教程参考地址:http://www.w3school.com.cn/js/index.asp
二、JavaScript基础
1)&nb ......
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>验证数字最简单<a href="http://www.jb51.net/list/list_6_1.htm" tar ......
一、概述
字符串在JavaScript中几乎无处不在,在你处理用户的输入数据的时候,在读取或设置DOM对象的属性时,在操作cookie时,当然还有更多...。JavaScript的核心部分提供了一组属性和方法用于通用的字符串操作,如分割字符串,改变字符串的大小写,操作子字符串等。
当前的 ......
今天小编和大家探讨的是JavaScript中自定义函数的用法,下面示例中的 Checktriplet 函数以三角形的边长为参数。通过查看三条边的长度是否可以组成一个毕达哥拉斯三元组(直角三角形斜边长度的平方等于其他两条边长的平方和)来计算该三角形是否为直角三角形。实际测试时 checkTriplet 函数要调用另两个函数中的一个函数。
......
首先创建解析对象:
try
{
xmldoc=new ActiveXObject("Microsoft.XMLDOM");//IE
}catch(e)
{
try{
xmldoc=document.implementation.createDocument("","",null);//非IE
}catch(e)
{
alert("无法创建对象!");
return;
}
}
xmldoc.async="false";
xmldoc.load(" ......