//****这是结合ASP(PHP),javascript,XML无限级Select下拉菜单控制程序,************//
//***********************源程序由CSDN网站搜集而来*****************************//
//*******************************源作者不明 **********************************//
//***********************如有问题,可联系QQ:40003394 **************************//
//***************************动指者:当海不再蓝 *******************************//
function KindXML(num){
 var i,j,arrText=[],arrValue=[],LastSelected,LastSelected_Effective;
 LastSelected = 0;
 LastSelected_Effective = 0;
 for(i=0;i<num;i++)
 {
   if(document.all(arrSel[i]).selectedIndex >= 0)//检测多级子类是否存在
   {
     arrText[i]=document.all(arrSel[i]).options[document.all(arrSel[i]).selectedIndex].text;
     arrValue[i]=document.all(arrSel[i]).options[document.all(arrSel[i]).selectedIndex].value;
     //设置最后的输出值
     if (arrValue[i] >= 0)
     {
     	  if (arrValue[i] > 0)
     	  {
     	  	LastSelected_Effective = arrValue[i];
     	  }
     	  LastSelected = arrValue[i];
     }
   }
   else
   {
     arrText[i] = "没有子类";
     arrValue[i] = -1;
   }
 }
 //输出最后设置值
 if(num==arrSel.length)
 {
   document.myform.ChooseKindID.value=LastSelected;//可自行修改对象document.myform.ChooseKindID,或屏蔽
   document.myform.ChooseKindID_Effective.value=LastSelected_Effective;
   return;
 }
 with(document.all(arrSel[num]))
 {
   length=0;
   var objText=document.all.xmldata.XMLDocument.childNodes[0];
   var objValue=document.all.xmldata.XMLDocument.childNodes[0];
   for(i=0;i<num;i++)
   {
     //检测XML库是否存在
     if(objText.selectSingleNode(arrSel[i]+'[@value="'+arrValue[i]+'"]') != null)
     {
     	  objText=objText.selectSingleNode(arrSel[i]+'[@text="'+arrText[i]+'"]');
     	  objValue=objValue.selectSingleNode(arrSel[i]+'[@value="'+arrValue[i]+'"]');
     }
   }
   //判断XML节点长度
   if (objValue.childNodes.length > 0)
   {
     //给select赋值
     for(i=0;i<objValue.childNodes.length;i++)
     {
       style.display="";
       options.add(document.createElement("OPTION")); 
       options[i].value=objValue.childNodes[i].getAttribute("value");
       options[i].text=objText.childNodes[i].getAttribute("text");
     }
   }
   else
   {
     options.add(document.createElement("OPTION")); 
     options[0].value=-1;
     options[0].text="没有子类";
     style.display="none";
   }
   onchange=new Function("KindXML("+(num+1)+")");
   onchange();
 }
}
