日期:2014-05-16  浏览次数:20390 次

数组输出的问题
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script language="javascript">
var str="过年时间:";
var a=new Array("1988","88","8");
for(var i=0;i<a.length;i++)
{ newstr=a[i]+"\n";
  god=str+newstr
}
document.write(god);
</script>

</head>

<body>
</body>
</html>


上面的代码是我测试一下,把数组按:“过年时间:1988 88 8”这种格式输出,按照上面写的,怎么只输出
过年时间:8,这个该怎么改??

------解决方案--------------------
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript">
var str = "过年时间:";
var a = new Array("1988", "88", "8");
for (var i = 0; i < a.length; i++) {
str+= a[i] + "\n";
}
document.write(str);
</script>

</head>

<body>
</body>
</html>