用XML实现无限级的(国家)省、市、区、县的动态关联

来源:互联网 发布:淘宝天猫开店流程 编辑:程序博客网 时间:2024/04/30 21:05
default.htm  
  -------------------------------------------------------------------  
  <html>  
  <head>  
  <title>用XML实现无限级的(国家)省、市、区、县的动态关联</title>  
  <meta   http-equiv="Content-Type"   content="text/html;   charset=gb2312">  
  <link   rel="stylesheet"   href="Common/style.css">  
  <script   language=javascript>  
  //________________________________________________________________  
  //****************************************************************  
  //     ╭═══════════════════════════════╮  
  //     ║     模块名称:用XML实现无限级的(国家)省、市、区、县的动态关联   ║  
  //     ║     作  者:发仔                       ║  
  //     ║     电子邮件:chenjf2k@163.com                                                                     ║  
  //     ║     演示地址:http://www.971411.com/test/default.htm                         ║  
  //     ╰═══════════════════════════════╯  
  //****************************************************************  
   
  var   oOrgData;  
  var   orgID="";  
  var   nodeParentOrg;  
  var   nodesEqualOrg;  
  var   nodesChildOrg;  
  function   window.onload(){  
          oOrgData   =   OrgData.XMLDocument.documentElement;  
          var   newOrgID   =   ""  
          if   (newOrgID!=""){  
                  orgID   =   newOrgID;  
          }  
          else{  
                  if   (oOrgData.childNodes.length>0){  
                          orgID   =   oOrgData.childNodes.item(0).getAttribute("编号");  
                  }  
          }  
          gotoOrg();  
  }  
  function   gotoOrg(){  
          checkBtnAble();  
          showOrgList();  
          showPage();  
  }  
  function   GoToParentOrgID(){  
          orgID   =   nodeParentOrg.getAttribute("编号")  
          gotoOrg();}  
  function   GoToChildOrgID(){  
          orgID   =   nodesChildOrg.item(0).getAttribute("编号")  
          gotoOrg();  
  }  
   
  function   showOrgList(){  
          removeItem();  
          var   oOption;  
          for(num=0;num<nodesEqualOrg.length;num++){  
                  oOption   =   document.createElement("OPTION");  
                  oOption.text="   "+nodesEqualOrg.item(num).getAttribute("名称");  
                  oOption.value=nodesEqualOrg.item(num).getAttribute("编号");  
                  if(oOption.value==orgID)   oOption.selected=true;  
                  orgList.add(oOption);  
          }  
  }  
  function   showPage(){  
          if   (orgList.options.length>0){  
                  orgID   =   orgList.options[orgList.selectedIndex].value;  
  //                 window.top.mainFrame.location.href='main.asp?orgID='+orgID;  
                  checkBtnAble();  
          }  
          else{  
  //                 window.top.mainFrame.location.href='main.asp';  
          }  
  }  
  function   removeItem(){  
          if   (orgList.options.length>0){  
                  for   (i   =   orgList.options.length   -   1;   i   >=   0;   --i){  
                          orgList.remove(i);  
                  }  
          }  
  }  
  function   checkBtnAble(){  
          var   parentOrgID;  
          if(orgID.length==3){  
                  parentOrgID="000";  
          }  
          else{  
                  parentOrgID=orgID.substring(0,orgID.length-3)  
          }  
          nodeParentOrg   =   oOrgData.selectSingleNode("机构[@编号='"+parentOrgID+"']")  
          if   (nodeParentOrg==null){  
                  btnParentOrgID.disabled=true;  
          }  
          else{  
                  btnParentOrgID.disabled=false;  
          }  
          nodesEqualOrg   =   oOrgData.selectNodes("机构[@上级编号='"+parentOrgID+"']")  
          nodesChildOrg   =   oOrgData.selectNodes("机构[@上级编号='"+orgID+"']")  
          if   (nodesChildOrg.length==0){  
                  document.all.btnChildOrgID.disabled=true;  
          }  
          else{  
                  document.all.btnChildOrgID.disabled=false;  
          }  
  }  
  </script>  
  <style>  
  input         {HEIGHT:   20px;border:   2px   outset;   background-color:   #005D99;   border-color:   #FFFFFF;   font-size:   10pt;color:   #FFFFFF}  
  select         {HEIGHT:   20px;   background-color:   #E6F7EE;   font-size:   10pt;color:   #000000}  
  td   {font-size:10pt}  
  </style>  
  </head>  
  <body   bgcolor="#FFFFFF"   text="#000000"   marginheight="0"   topmargin="6">  
  <xml   id="OrgData"   src="Orglist.xml"></xml>    
  <table   width="100%"   border="0"   cellpadding="0"   cellspacing="0">  
      <tr>    
          <td   bgcolor="005D99"   height="30"><font   color="#FFFFFF">&nbsp;当前操作单位:</font>    
              <input   type="button"   value="&lt;&lt;"   onClick="GoToParentOrgID()"   id="btnParentOrgID"   title="返回上一级管理"   disabled>  
              <select   id="orgList"   style="WIDTH:   475px;"   title="请选择当前操作单位"   onChange="javascript:showPage()">  
              </select>  
              <input   type="button"   value="&gt;&gt;"   onClick="GoToChildOrgID()"   id="btnChildOrgID"   title="进入下一级管理"   disabled>  
          </td>  
      </tr>  
  </table>  
  </body>  
  </html>  
   
   
  OrgList.xml   [以下只简单列举几个单位]  
  --------------------------------------------------------------  
  <?xml   version="1.0"   encoding="gb2312"?>  
   
  <机构列表>  
      <机构   编号="001"   名称="福建省"   上级编号="000"/>  
      <机构   编号="001001"   名称="福建省->省机关"   上级编号="001"/>  
      <机构   编号="001001016"   名称="福建省->省机关->办公室"   上级编号="001001"/>  
      <机构   编号="001001017"   名称="福建省->省机关->科研所"   上级编号="001001"/>  
      <机构   编号="001001018"   名称="福建省->省机关->信息处"   上级编号="001001"/>  
      <机构   编号="001002"   名称="福建省->福州市"   上级编号="001"/>  
      <机构   编号="001002021"   名称="福建省->福州市->局机关"   上级编号="001002"/>  
      <机构   编号="001002021001"   名称="福建省->福州市->局机关->局领导"   上级编号="001002021"/>  
      <机构   编号="001002021002"   名称="福建省->福州市->局机关->办公室"   上级编号="001002021"/>  
      <机构   编号="001002021003"   名称="福建省->福州市->局机关->计财室"   上级编号="001002021"/>  
      <机构   编号="001002005"   名称="福建省->福州市->仓山区"   上级编号="001002"/>  
      <机构   编号="001002006"   名称="福建省->福州市->鼓楼区"   上级编号="001002"/>  
      <机构   编号="001002001"   名称="福建省->福州市->台江区"   上级编号="001002"/>  
      <机构   编号="001002004"   名称="福建省->福州市->晋安区"   上级编号="001002"/>  
      <机构   编号="001002010"   名称="福建省->福州市->闽侯县"   上级编号="001002"/>  
      <机构   编号="001002015"   名称="福建省->福州市->开发区"   上级编号="001002"/>  
      <机构   编号="001002012"   名称="福建省->福州市->闽清县"   上级编号="001002"/>  
      <机构   编号="001002011"   名称="福建省->福州市->永泰县"   上级编号="001002"/>  
      <机构   编号="001002007"   名称="福建省->福州市->长乐市"   上级编号="001002"/>  
      <机构   编号="001002018"   名称="福建省->福州市->连江县"   上级编号="001002"/>  
      <机构   编号="001002017"   名称="福建省->福州市->福清市"   上级编号="001002"/>  
      <机构   编号="001002016"   名称="福建省->福州市->平潭县"   上级编号="001002"/>  
      <机构   编号="001002008"   名称="福建省->福州市->罗源县"   上级编号="001002"/>  
      <机构   编号="001002020"   名称="福建省->福州市->琅岐分局"   上级编号="001002"/>  
      <机构   编号="001003"   名称="福建省->厦门市"   上级编号="001"/>  
      <机构   编号="001003015"   名称="福建省->厦门市->市局机关"   上级编号="001003"/>  
      <机构   编号="001003012"   名称="福建省->厦门市->直征局"   上级编号="001003"/>  
      <机构   编号="001003013"   名称="福建省->厦门市->外税分局"   上级编号="001003"/>  
      <机构   编号="001003014"   名称="福建省->厦门市->稽查分局"   上级编号="001003"/>  
      <机构   编号="001003016"   名称="福建省->厦门市->信息技术分局"   上级编号="001003"/>  
      <机构   编号="001003002"   名称="福建省->厦门市->开元区局"   上级编号="001003"/>  
      <机构   编号="001003003"   名称="福建省->厦门市->思明区局"   上级编号="001003"/>  
      <机构   编号="001003006"   名称="福建省->厦门市->湖里区局"   上级编号="001003"/>  
      <机构   编号="001003007"   名称="福建省->厦门市->集美区局"   上级编号="001003"/>  
      <机构   编号="001003008"   名称="福建省->厦门市->杏林区局"   上级编号="001003"/>  
      <机构   编号="001003009"   名称="福建省->厦门市->海沧投资区局"   上级编号="001003"/>  
      <机构   编号="001003011"   名称="福建省->厦门市->同安区局"   上级编号="001003"/>  
      <机构   编号="001003004"   名称="福建省->厦门市->鼓浪屿区局"   上级编号="001003"/>  
      <机构   编号="001003017"   名称="福建省->厦门市->税务学会"   上级编号="001003"/>  
  </机构列表>   
  
 摘自:http://topic.csdn.net/t/20050102/13/3694194.html