数组的问题!

zl13 2004-03-10 02:58:03
我在数组中的存储方式是"('100007')",我现在想把数组中的最大值取出来并加1,可出来的却是字符串相加了,我是不是要进行一下转换?

代码如下:
<%
'从数据库中读出数据,打印成Javascript数组
dim stra,strb,strc,i
set rs = server.createobject("adodb.recordset")
sql = "select number from project"
i = 0
rs.open sql,conn,1,1
response.write "<script language='Javascript'>"+chr(10)
strb = "var array1 = new Array("
while not rs.eof
if i <> rs.RecordCount - 1 then
stra = stra + chr(34) + "('" + rs("number") + "')" + chr(34) + ","
i = i + 1
else
stra = stra + chr(34) + "('" + rs("number") + "')" + chr(34)
end if
rs.movenext
wend

strc = strb + stra + ");"
response.write strc
response.write "</script>"
rs.close
set rs = nothing


%>

<script language=Javascript>
function test(x){
var j = 0;
var max = 0;
for(var i = 0; i < array1.length; i++){ //循环array1数组
var str = array1[i].substring(2,4); //取数组中元素的头两位
if (x == str){ //x为传递的城市编号
if (j == 0) //j为判断max是否被覆值
{
max = array1[i];
j = j + 1;
}
if (j != 0)
{
if (max < array1[i])
{
max = array1[i]; //得出array1中的最大值
}
}
}
}
document.writeln(max + 1);
var result = max.replace("(",";");
result = max.replace("(",";");
document.write(result);
}
test("30");
</script>
...全文
20 点赞 收藏 6
写回复
6 条回复
切换为时间正序
请发表友善的回复…
发表回复

还没有回复,快来抢沙发~

发动态
发帖子
JavaScript
创建于2007-09-28

8.4w+

社区成员

Web 开发 JavaScript
申请成为版主
社区公告
暂无公告