在用javascript做客户端的,下拉框关联时,关联数据库的表超过三千条(行),就出现错误提示。
个人怀疑是数组长度的上限所至,请各位高手指教!
代码如下:
<script language = "JavaScript">  
  <%
  '打开专业表,第二层
  dim   rs,sql,count,rs1,sql1
  sql = "select * from district order by locationid asc"   
  set rs = conn.execute(sql)   
  %>   
  //第二层,数组表   
  var onecount;   
  onecount=0;   
  subcat = new Array();   
  <%   
  count = 0   
  do while not rs.eof     
  %>   
  subcat[<%=count%>] = new Array("<%= trim(rs("districtname"))%>","<%= trim(rs("locationid"))%>","<%= trim(rs("districtid"))%>");   
  <%   
  count = count + 1   
  rs.movenext   
  loop   
  rs.close   
  set rs=nothing  
  %>   
  onecount=<%=count%>;   
  //获得第二层选项
  function changelocation(locationid)   
  {   
   document.myform.smalllocation.length = 0;     
   var locationid=locationid;   
   var i;   
   document.myform.smalllocation.options[0] = new Option('====所有地区====','0');   
   for (i=0;i < onecount; i++)   
        {   
          if   (subcat[i][1]   ==   locationid)   
           {     
             document.myform.smalllocation.options[document.myform.smalllocation.length] = new Option(subcat[i][0], subcat[i][2]);   
            }                   
         }   
                    
  }  
</script>
当"district"表里的数据超过三千多条,就会出现错误。低于三千条,就正常。
请问高手们,怎样解决?
能否把“数组”的的上限提高,怎样提高,怎样写?
还有有什么办法能解决?

解决方案 »

  1.   

    document.myform.smalllocation.length = 0;
    应该是
    document.myform.smalllocation.options.length = 0;
    用3500条测试正常,只是有点慢。<!DOCTYPE html >
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <script type="text/javascript">
    window.onload = function(){
    var sel = document.getElementById("sel");
    for(var i = 0; i < 3500; i++){
    sel.options[i] =  new Option(i, i);
    }
    };
    </script>
    </head><body>
    <div id="container"><select id="sel"></select></div>
    </body>
    </html>
      

  2.   

    document.myform.smalllocation.options.length = 0;