动态无限级关联下拉菜单    

JS文件

function SaveCache(){
   //设置缓存过期时间//
    var oTimeNow = new Date();
   oTimeNow.setMinutes(oTimeNow.getMinutes() + 1);
   var sExpirationDate = oTimeNow.toUTCString();
  
  var listData=document.getElementById("List") 
   listData.expires=sExpirationDate;
   listData.setAttribute("listInnerHtml",listData.innerHTML);
   listData.setAttribute("listValue",form1.CurrentNodeID.value)
   listData.save("myCache");   
};

function BuildList(){
   var NodeID;
  
   //获出节点//
   if (event.srcElement){
      NodeID=event.srcElement.value;
   }else{
      NodeID=0;
   }

   //获取缓存//
   var listData=document.getElementById("List")
   listData.load("myCache");
   cacheData=listData.getAttribute("listInnerHtml")
   var listValue=listData.getAttribute("listValue")

   //缓存载入判断//  
   if (NodeID==0 && cacheData!=null){
      form1.CurrentNodeID.value=listValue;
      document.getElementById("List").innerHTML=cacheData;
      for(var j=0;j      var listObj=document.all.tags("select")[j];
        listObj.attachEvent("onchange",function(){BuildList()});
      };
   }else{
      if (NodeID!=null){
         var nodeLength;
         var listObj;
      var listItem;
      var nodeObj;
      var myErr;
      var i=0;
        var j=0;
      var listIndex=0;
      var listCount;

         //清空缓存//
        var listData=document.getElementById("List")
      if(listData.getAttribute("listInnerHtml")!=null){
        listData.removeAttribute("listInnerHtml");
            listData.save("myCache");  
         }
         
         //赋值//

      document.getElementById("CurrentNodeID").value=NodeID;
      listCount=document.all.tags("select").length

         //读取子栏目数据//
         var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
         xmlDoc.async = false;
         xmlDoc.load("getNodeXml.asp?NodeID="+ NodeID +"");

         if (xmlDoc.parseError.errorCode != 0) {
            myErr = xmlDoc.parseError;
            alert("XML载入失败!" + myErr.reason);
         } else {
            nodeObj=xmlDoc.getElementsByTagName("Node");
            nodeLength=nodeObj.length;
            currNode = xmlDoc.documentElement.childNodes.item(0);
         };

         //获取当前下拉列表索引值//
         for(listIndex=0;listIndex<=listCount;listIndex++){
           if (document.all.tags("select")[listIndex]==event.srcElement){
         break;
      };
       };
     
      //列表移除//
         if (listIndex+1<=listCount){

            for (j=listCount-1;j>listIndex;j--){
      if (document.all.tags("select")[j].id.indexOf("TreeList")==0){     
                 document.all.tags("select")[j].removeNode(true);
               };
         };
         };
              
      //列表建立//
      if (nodeLength!=0){
            listObj = document.createElement("select")
            listObj.id="TreeList";
            listObj.attachEvent("onchange",function(){BuildList()});
            listObj.options[listObj.options.length++] = new Option("所属栏目","");
           for (i=0;i               listObj.options[listObj.options.length++] = new Option(nodeObj.item(i).childNodes[1].text,nodeObj.item(i).childNodes[0].text);
         };
            List.appendChild(listObj); 
         };
      };
   };
};

function SetFontSize(Size){
   var Obj=document.getElementById("Body")
   switch (Size){
      case "S":
    Obj.className="Content_Small";
       break;
      case "M":
    Obj.className="Content_Middle";
       break;
      case "L":
    Obj.className="Content_Large";     
       break;
   }
}

ASP文件



<%
Response.Expires=0
Response.ExpiresAbsolute
Response.Clear
'Response.Expires=0
'response.end

dim NodeID
dim SQL
dim RS

NodeID=request("NodeID")

SQL="select NodeID,NodeName from NodeTable where BelongNodeID="& NodeID &""

set RS=conn.execute(SQL)

response.write "" & chr(13)
response.write "" & chr(13)
while not RS.eof
   response.write "" & chr(13)
   response.write ""& RS("NodeID") &"" & chr(13)
   response.write ""& RS("NodeName") &"" & chr(13)
   response.write "
" & chr(13)  
   RS.movenext
wend
response.write "
" & chr(13)
%>

代码下载

演示地址是:

http://www.whcgch.com/persionalweb/jowing/js/ilist/ItemAdd.asp

下载:
http://www.whcgch.com/persionalweb/jowing/js/ilist/ilist.rar

关联文档