<script>var a=""<%set rs=server.CreateObject("adodb.recordset")sql="select * from pdtbc where id<>1"rs.open sql,conn,1,3js=0do while not rs.eof%>provice<%=js%>="<%=rs("id")%>,<%=rs("title")%>";var a = a + provice<%=js%>+',';<%rs.movenextjs=js+1loop %>var provice = new Array(a);</script>我用如上代码从数据库里读出产品的类别~并把他放入provice数组,之后想通过以下代码生成下拉菜单,function getCountrySelect(classStyle,id,name,provinceid,cityid,realValue,defaultValue){var htmlStr = '<select class="'+classStyle+'" id="'+id+'" name="'+name+'">';for(i=0;i<provice.length;i++){var selected = '';var valueArray = provice[i].split(",");if(realValue!=null&&realValue!=''&&realValue!='-1'){var countrystr = realValue.substring(0,3)+"00000";if(countrystr==valueArray[0]){selected = 'selected="selected"';}}else if(realValue==null||realValue==''||realValue=='-1'){if(defaultValue==valueArray[0]){selected = 'selected="selected"';}}htmlStr = htmlStr + '<option value="'+valueArray[0]+'" '+selected+'>'+valueArray[1]+'</option>';}htmlStr = htmlStr + '</select>';document.write(htmlStr);}可是生成的菜单却只显示第一项,我检查了一下~发现是因为provice.length等于1可是document.write(provice);却能读出所有项~那为什么provice.length还是等于1呢~~~
1 回答
白板的微信
TA贡献1883条经验 获得超3个赞
第一部分代码出了问题,你可以这样写:
<script>
var provice = new Array();
<%
set rs=server.CreateObject("adodb.recordset")
sql="select * from pdtbc where id<>1"
rs.open sql,conn,1,3
js=0
do while not rs.eof%>
provice[<%=js%>]="<%=rs("id")%>,<%=rs("title")%>";
<%rs.movenext
js=js+1
loop %>
</script>
添加回答
举报
0/150
提交
取消