ASP + JS数组的问题~~~高手帮帮忙~~~急啊~~
<script>vara=""<%setrs=server.CreateObject("adodb.recordset")sql="select*frompdtbcwhe...
<script>
var a=""
<%
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")%>";
var a = a + provice<%=js%>+',';
<%rs.movenext
js=js+1
loop %>
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呢~~~
很急~~~有能办法能解决~~~高手们帮帮忙~~~~~~~ 展开
var a=""
<%
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")%>";
var a = a + provice<%=js%>+',';
<%rs.movenext
js=js+1
loop %>
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呢~~~
很急~~~有能办法能解决~~~高手们帮帮忙~~~~~~~ 展开
2个回答
展开全部
第一部分代码出了问题,你可以这样写:
<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>
<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>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询