用循环,给你段C#的代码,你转换一下
<script language=javascript>
var tofieldListArray=new Array();
<%
for(int i=0;i<rs.count;i++)
{
Response.Write("tofieldListArray[" + i + "]=" + rs[i]["字段名"].ToString());
}
%>
</script>
就是这个意思,呵呵,你看着用vbscript改写吧
<script language=javascript>
var tofieldListArray=new Array();
<%
for(int i=0;i<rs.count;i++)
{
Response.Write("tofieldListArray[" + i + "]=" + rs[i]["字段名"].ToString());
}
%>
</script>
就是这个意思,呵呵,你看着用vbscript改写吧
解决方案 »
- JS排序问题
- 应用jquery实现 当点击一句话时会弹出一个Tab页,当在点击这句话时如何已有之前已经打开了Tab页 无需在重新打开一个新的 直接打开之前的就好
- 兼容性问题。请问如何解决。
- 我遇到一个非常奇怪的问题,click会有两次连接动作
- 修改火狐兼容问题啊!!! 谁会来看看,很锻炼你的技术啊!!!
- 如何为div动态滴设置onclick事件。
- 求助,关于DIV模拟select的问题
- 谁用过jqgrid的cell editing?
- 请叫JS生成表格后,超难问题,高手过来看看!!!! 分不够再加
- 关于数据的有效性校验??? 怎么完成!!!
- 不明白问题,window.createPopup() 弹出的内容,怎么隐藏?
- 求一个跨框架的多级菜单,在线等。
在ASP里面调用
for i = 0 to rs.recordcount
response.write("<script>")
response.write("inArray('" & rs(0) & "','" & rs(1) & "')")
response.write("</script>")
next
{
this.字段1 = 字段1;
this.字段2 = 字段2;
......
}function inArray(字段1,字段2.....)
{
var iCount = Array.length;
Array[iCount] = new Array(字段1,字段2.....)
}
response.write("<script>")
response.write("inArray('" & rs(0) & "','" & rs(1) & "')")
response.write("</script>")
next
dim count
set rs=server.CreateObject("ADODB.RecordSet")
sql="select * from biao"
rs.open sql,conn,1,3
%>
<script language = "JavaScript">
var tofieldListArray=new Array();
<%
count = 0
do while not rs.eof
%>
tofieldListArray[<%=count%>] = <%= rs(0)%>
//如果字段是字符串类型,改成<%= cStr(rs(0))%>
<%
count = count + 1
rs.movenext
loop
rs.close
set rs=nothing
%>
</script>
这个要看你是几维的数组了,如果是二维数组,就像这样写
response.write("inArray('" & rs(字段1) & "','" & rs(字段2) & "')")
下面是JSfunction arr(字段1,字段2.....)
{
this.字段1 = 字段1;
this.字段2 = 字段2;
......
}
var arr = New Array()
function inArray(字段1,字段2.....)
{
var iCount = arr.length;
arr[iCount] = new arr(字段1,字段2.....)
}
因为js是客户端的,而你的rs在服务器端
所以你要让rs变成客户端数组的话只能通过Response.Write来输出语句
这些语句到了客户端就会变成你定义数组内容的语句
你可以输出然后查看客户端源代码看一下具体效果,这样比较容易明白
var tofieldListArray=new Array();
<%
set rs=server.CreateObject("ADODB.RecordSet")
sql="select * from biao"
rs.open sql,conn,1,3
i = 0
do while not rs.eof
%>
tofieldListArray[<%=i%>] = "<%=rs.fields("fieldsName")%=>"
<%
i = i+1
rs.movenext
loop
%>
</script>