我的程序中要实现省市联动,可是为什么总是出现stack overflow at line:xxx?
我的代码如下:我觉得好像是removeAllList(noRemoveValue)函数的问题,可是不知道怎么改啊!求大家帮忙看一下什么毛病哈!先谢谢啦!
<script>
function removeAllList(noRemoveValue)
{
  var objObject = unitInfoForm.citycode;
  var objLen = objObject.length;
  for (var i=0;i<objLen;i++)
  {
if ( objObject.options[i].value != noRemoveValue)
{
      objObject.options.remove(i);
      removeAllList(noRemoveValue);
      break;
    }
  }
}
function removeAllListSource(noRemoveValue)
{
    var objSource = document.unitInfoForm.citycode;
    if(objSource.length!=undefined && objSource.length>=0)  
    {
   var objLen = objSource.length;
   for (var i=0;i<objLen;i++)
   {
     if(objSource.options[i].value != noRemoveValue)
     {
       objSource.options.remove(i);
       removeAllListSource(noRemoveValue);
       break;
     }
   }
  }

function addtolist(obj,value,label)
{
   obj.add(new Option(value,label));
}
function change()
{
var objSource =document.unitInfoForm.citycode;
   removeAllListSource();
    userarray = new Array();
    userarray1= new Array();
    deparray = new Array();      
<%

for(int j=0;j<list2.size();j++)
{
out.println("userarray["+j+"]='"+((Citycode)list2.get(j)).getCityname()+"';");
out.println("userarray1["+j+"]='"+((Citycode)list2.get(j)).getCitycode()+"';");
out.println("deparray["+j+"]='"+((Citycode)list2.get(j)).getFlagpro()+"';");
}
%> for(var i=0;i<userarray.length;i++)
{
   if (deparray[i]==document.unitInfoForm.provincecode.value || document.unitInfoForm.provincecode.value=="1000")
   {
addtolist(objSource,userarray[i],userarray1[i]);
}
}
}
</script><html:select property="provincecode" style="width:90px;" value="北京" onchange="change()">
<html:select property="citycode" style="width:120px;" value="北京" >

解决方案 »

  1.   

    是死循环了.你这个是要干啥呢removeAllListSource
      

  2.   

    呵呵,我是抄原来程序的代码,是别人编的。我也不太懂,只知道是死循环不知道怎么改。能帮忙改一下吗?谢谢了。现在联动已经实现了,没用JS只用的JSP!不过还是想请教高人帮忙看看是哪里的问题,并把正确的代码写出来好吗?
      

  3.   

    function   removeAllListSource(noRemoveValue) 

            var   objSource   =   document.unitInfoForm.citycode; 
            if(objSource.length!=undefined &&   objSource.length >=0)     
            { 
        var   objLen   =   objSource.length; 
        for   (var   i=0;i <objLen;i++) 
        { 
            if(objSource.options[i].value != noRemoveValue) 
            { 
                objSource.options.remove(i); 
            } 
        } 
      } 
    }
    function   addtolist(obj,value,label) 

        obj.add(new   Option(value,label)); 

    function   change() 

    var   objSource   =document.unitInfoForm.citycode; 
        removeAllListSource(); 
            userarray   =   new   Array(); 
          userarray1=   new   Array(); 
            deparray   =   new   Array();             
    <% for(int   j=0;j <list2.size();j++) 

    out.println("userarray["+j+"]= ""+((Citycode)list2.get(j)).getCityname()+" ";"); 
    out.println("userarray1["+j+"]= ""+((Citycode)list2.get(j)).getCitycode()+" ";"); 
    out.println("deparray["+j+"]= ""+((Citycode)list2.get(j)).getFlagpro()+" ";"); 

    % > for(var   i=0;i <userarray.length;i++) 

        if   (deparray[i]==document.unitInfoForm.provincecode.value   ¦ ¦   document.unitInfoForm.provincecode.value=="1000") 
        { 
    addtolist(objSource,userarray[i],userarray1[i]); 



    </script > <html:select   property="provincecode"   style="width:90px;"   value="北京"   onchange="change()" > 
    <html:select   property="citycode"   style="width:120px;"   value="北京"   >
    </BODY>
    </HTML>